textLinesMutator: Fix insertions at the end of `lines`
The new insertions are directly pushed to curSplice now instead of trying to incorporate an undefined line into the splice, which would result in an error: TypeError: Cannot read property 'substring' of undefinedfix-textlinesmutator
parent
535331aa17
commit
f7cd233069
|
@ -983,11 +983,17 @@ class TextLinesMutator {
|
||||||
this._curSplice.push(...newLines);
|
this._curSplice.push(...newLines);
|
||||||
this._curLine += newLines.length;
|
this._curLine += newLines.length;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!this.hasMore()) {
|
||||||
// There are no additional lines. Although the line is put into splice, curLine is not
|
// There are no additional lines. Although the line is put into splice, curLine is not
|
||||||
// increased because there may be more chars in the line (newline is not reached).
|
// increased because there may be more chars in the line (newline is not reached). We are
|
||||||
|
// inserting at the end of lines. curCol is 0 as curLine is not in splice.
|
||||||
|
this._curSplice.push(text);
|
||||||
|
this._curCol += text.length;
|
||||||
|
} else {
|
||||||
|
// insert text after curCol
|
||||||
const sline = this._putCurLineInSplice();
|
const sline = this._putCurLineInSplice();
|
||||||
if (!this._curSplice[sline]) {
|
if (!this._curSplice[sline]) {
|
||||||
|
// TODO should never happen now
|
||||||
const err = new Error(
|
const err = new Error(
|
||||||
'curSplice[sline] not populated, actual curSplice contents is ' +
|
'curSplice[sline] not populated, actual curSplice contents is ' +
|
||||||
`${JSON.stringify(this._curSplice)}. Possibly related to ` +
|
`${JSON.stringify(this._curSplice)}. Possibly related to ` +
|
||||||
|
|
|
@ -160,6 +160,25 @@ describe('easysync-mutations', function () {
|
||||||
['insert', 'z'],
|
['insert', 'z'],
|
||||||
], ['fuz']);
|
], ['fuz']);
|
||||||
|
|
||||||
|
// #2836, #5214, #3560 regressions
|
||||||
|
runMutationTest(11, ['\n'], [
|
||||||
|
['remove', 1, 1, '\n'],
|
||||||
|
['insert', 'c', 0],
|
||||||
|
], ['c']);
|
||||||
|
|
||||||
|
runMutationTest(12, ['\n'], [
|
||||||
|
['remove', 1, 1, '\n'],
|
||||||
|
['insert', 'a\n', 1],
|
||||||
|
['insert', 'c'],
|
||||||
|
], ['a\n', 'c']);
|
||||||
|
|
||||||
|
runMutationTest(13, ['\n', 'fun\n', '\n'], [
|
||||||
|
['remove', 1, 1, '\n'],
|
||||||
|
['skip', 4, 1, false],
|
||||||
|
['remove', 1, 1, '\n'],
|
||||||
|
['insert', 'c'],
|
||||||
|
], ['fun\n', 'c']);
|
||||||
|
|
||||||
it('mutatorHasMore', async function () {
|
it('mutatorHasMore', async function () {
|
||||||
const lines = ['1\n', '2\n', '3\n', '4\n'];
|
const lines = ['1\n', '2\n', '3\n', '4\n'];
|
||||||
let mu;
|
let mu;
|
||||||
|
|
Loading…
Reference in New Issue