Skip to content

Commit 2cb67d4

Browse files
webzwo0irhansen
authored andcommitted
textLinesMutator: Fix removal at the end of the lines array
...in case we are in the middle of a line (curCol !== 0) and we remove everything up to the end of the line.
1 parent 9e658a7 commit 2cb67d4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/static/js/Changeset.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,20 +904,24 @@ class TextLinesMutator {
904904
let removed = '';
905905
if (this._isCurLineInSplice()) {
906906
if (this._curCol === 0) {
907+
// First line to be removed is in splice.
907908
removed = this._curSplice[this._curSplice.length - 1];
908909
this._curSplice.length--;
910+
// Next lines to be removed are not in splice.
909911
removed += nextKLinesText(L - 1);
910912
this._curSplice[1] += L - 1;
911913
} else {
912914
removed = nextKLinesText(L - 1);
913915
this._curSplice[1] += L - 1;
914916
const sline = this._curSplice.length - 1;
915917
removed = this._curSplice[sline].substring(this._curCol) + removed;
916-
this._curSplice[sline] = this._curSplice[sline].substring(0, this._curCol) +
917-
this._linesGet(this._curSplice[0] + this._curSplice[1]);
918-
this._curSplice[1] += 1;
918+
// Is there a line left?
919+
const remaining = this._linesGet(this._curSplice[0] + this._curSplice[1]) || '';
920+
this._curSplice[sline] = this._curSplice[sline].substring(0, this._curCol) + remaining;
921+
this._curSplice[1] += remaining ? 1 : 0;
919922
}
920923
} else {
924+
// Nothing that is removed is in splice. Implies curCol === 0.
921925
removed = nextKLinesText(L);
922926
this._curSplice[1] += L;
923927
}

0 commit comments

Comments
 (0)