mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
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 undefined
This commit is contained in:
parent
fe5d43871f
commit
01b04a6f92
2 changed files with 27 additions and 2 deletions
|
@ -983,11 +983,17 @@ class TextLinesMutator {
|
|||
this._curSplice.push(...newLines);
|
||||
this._curLine += newLines.length;
|
||||
}
|
||||
} else {
|
||||
} else if (!this.hasMore()) {
|
||||
// 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();
|
||||
if (!this._curSplice[sline]) {
|
||||
// TODO should never happen now
|
||||
const err = new Error(
|
||||
'curSplice[sline] not populated, actual curSplice contents is ' +
|
||||
`${JSON.stringify(this._curSplice)}. Possibly related to ` +
|
||||
|
|
|
@ -160,6 +160,25 @@ describe('easysync-mutations', function () {
|
|||
['insert', 'z'],
|
||||
], ['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 () {
|
||||
const lines = ['1\n', '2\n', '3\n', '4\n'];
|
||||
let mu;
|
||||
|
|
Loading…
Reference in a new issue