Skip to content

Commit 21a8912

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 5061fe7 commit 21a8912

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
@@ -973,8 +973,9 @@ class TextLinesMutator {
973973
this._curLine += newLines.length;
974974
// insert the remaining chars from the "old" line (e.g. the line we were in
975975
// when we started to insert new lines)
976-
this._curSplice.push(theLine.substring(lineCol));
977-
this._curCol = 0; // TODO(doc) why is this not set to the length of last line?
976+
const remaining = theLine.substring(lineCol);
977+
if (remaining !== '') this._curSplice.push(remaining);
978+
this._curCol = 0;
978979
} else {
979980
this._curSplice.push(...newLines);
980981
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)