Skip to content

Commit 243d4ae

Browse files
committed
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 43de73d commit 243d4ae

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/static/js/Changeset.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,20 +835,25 @@ exports.textLinesMutator = (lines) => {
835835
};
836836
if (isCurLineInSplice()) {
837837
if (curCol === 0) {
838+
// first line to be removed is in splice
838839
removed = curSplice[curSplice.length - 1];
839840
curSplice.length--;
841+
// next lines to be removed are not in splice
840842
removed += nextKLinesText(L - 1);
841843
curSplice[1] += L - 1;
842844
} else {
843845
removed = nextKLinesText(L - 1);
844846
curSplice[1] += L - 1;
845847
const sline = curSplice.length - 1;
846848
removed = curSplice[sline].substring(curCol) + removed;
847-
curSplice[sline] = curSplice[sline].substring(0, curCol) +
848-
linesGet(curSplice[0] + curSplice[1]);
849-
curSplice[1] += 1;
849+
// is a line left?
850+
const remaining = linesGet(curSplice[0] + curSplice[1]) || '';
851+
curSplice[sline] = curSplice[sline].substring(0, curCol) + remaining;
852+
curSplice[1] += remaining ? 1 : 0;
850853
}
851854
} else {
855+
// nothing that is removed is in splice
856+
// implies curCol === 0
852857
removed = nextKLinesText(L);
853858
curSplice[1] += L;
854859
}

0 commit comments

Comments
 (0)