Skip to content

Commit c558d79

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 f38f2f3 commit c558d79

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
@@ -813,20 +813,24 @@ const textLinesMutator = (lines) => {
813813
let removed = '';
814814
if (isCurLineInSplice()) {
815815
if (curCol === 0) {
816+
// First line to be removed is in splice.
816817
removed = curSplice[curSplice.length - 1];
817818
curSplice.length--;
819+
// Next lines to be removed are not in splice.
818820
removed += nextKLinesText(L - 1);
819821
curSplice[1] += L - 1;
820822
} else {
821823
removed = nextKLinesText(L - 1);
822824
curSplice[1] += L - 1;
823825
const sline = curSplice.length - 1;
824826
removed = curSplice[sline].substring(curCol) + removed;
825-
curSplice[sline] = curSplice[sline].substring(0, curCol) +
826-
linesGet(curSplice[0] + curSplice[1]);
827-
curSplice[1] += 1;
827+
// Is there a line left?
828+
const remaining = linesGet(curSplice[0] + curSplice[1]) || '';
829+
curSplice[sline] = curSplice[sline].substring(0, curCol) + remaining;
830+
curSplice[1] += remaining ? 1 : 0;
828831
}
829832
} else {
833+
// Nothing that is removed is in splice. Implies curCol === 0.
830834
removed = nextKLinesText(L);
831835
curSplice[1] += L;
832836
}

0 commit comments

Comments
 (0)