Skip to content

Commit 06f7124

Browse files
webzwo0irhansen
authored andcommitted
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 f7cd233 commit 06f7124

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
@@ -977,8 +977,9 @@ class TextLinesMutator {
977977
this._curLine += newLines.length;
978978
// insert the remaining chars from the "old" line (e.g. the line we were in
979979
// when we started to insert new lines)
980-
this._curSplice.push(theLine.substring(lineCol));
981-
this._curCol = 0; // TODO(doc) why is this not set to the length of last line?
980+
const remaining = theLine.substring(lineCol);
981+
if (remaining !== '') this._curSplice.push(remaining);
982+
this._curCol = 0;
982983
} else {
983984
this._curSplice.push(...newLines);
984985
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)