Skip to content

Commit

Permalink
textLinesMutator: Fix insertions with newlines at the end of a line
Browse files Browse the repository at this point in the history
In such cases the remaining part of the old line is directly pushed to
the splice but we need to ensure it is not an empty string.
Before this commit an empty string was pushed to the splice.
  • Loading branch information
webzwo0i committed Nov 29, 2021
1 parent 5061fe7 commit 21a8912
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/static/js/Changeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,9 @@ class TextLinesMutator {
this._curLine += newLines.length;
// insert the remaining chars from the "old" line (e.g. the line we were in
// when we started to insert new lines)
this._curSplice.push(theLine.substring(lineCol));
this._curCol = 0; // TODO(doc) why is this not set to the length of last line?
const remaining = theLine.substring(lineCol);
if (remaining !== '') this._curSplice.push(remaining);
this._curCol = 0;
} else {
this._curSplice.push(...newLines);
this._curLine += newLines.length;
Expand Down
5 changes: 5 additions & 0 deletions src/tests/frontend/specs/easysync-mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ describe('easysync-mutations', function () {
['insert', 'c'],
], ['fun\n', 'c']);

runMutationTest(14, ['\n'], [
['remove', 1, 1, '\n'],
['insert', 'a'],
['insert', 'c\n', 1],
], ['ac\n']);
it('mutatorHasMore', async function () {
const lines = ['1\n', '2\n', '3\n', '4\n'];
let mu;
Expand Down

0 comments on commit 21a8912

Please sign in to comment.