Skip to content

Commit 6d96eed

Browse files
committed
textLinesMutator: Fix insertions with newlines at the end of a line
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.
1 parent 6da879d commit 6d96eed

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/static/js/Changeset.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,9 @@ class TextLinesMutator {
976976
this._curLine += newLines.length;
977977
// insert the remaining chars from the "old" line (e.g. the line we were in
978978
// when we started to insert new lines)
979-
this._curSplice.push(theLine.substring(lineCol));
980-
this._curCol = 0; // TODO(doc) why is this not set to the length of last line?
979+
const remaining = theLine.substring(lineCol);
980+
if (remaining !== '') this._curSplice.push(remaining);
981+
this._curCol = 0;
981982
} else {
982983
this._curSplice.push(...newLines);
983984
this._curLine += newLines.length;

src/tests/frontend/specs/easysync-mutations.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ describe('easysync-mutations', function () {
179179
['insert', 'c'],
180180
], ['fun\n', 'c']);
181181

182+
runMutationTest(14, ['\n'], [
183+
['remove', 1, 1, '\n'],
184+
['insert', 'a'],
185+
['insert', 'c\n', 1],
186+
], ['ac\n']);
182187
it('mutatorHasMore', async function () {
183188
const lines = ['1\n', '2\n', '3\n', '4\n'];
184189
let mu;

0 commit comments

Comments
 (0)