Skip to content

Commit 0af1eea

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 9ce7a26 commit 0af1eea

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
@@ -844,20 +844,25 @@ exports.textLinesMutator = (lines) => {
844844
};
845845
if (isCurLineInSplice()) {
846846
if (curCol === 0) {
847+
// first line to be removed is in splice
847848
removed = curSplice[curSplice.length - 1];
848849
curSplice.length--;
850+
// next lines to be removed are not in splice
849851
removed += nextKLinesText(L - 1);
850852
curSplice[1] += L - 1;
851853
} else {
852854
removed = nextKLinesText(L - 1);
853855
curSplice[1] += L - 1;
854856
const sline = curSplice.length - 1;
855857
removed = curSplice[sline].substring(curCol) + removed;
856-
curSplice[sline] = curSplice[sline].substring(0, curCol) +
857-
linesGet(curSplice[0] + curSplice[1]);
858-
curSplice[1] += 1;
858+
// is a line left?
859+
const remaining = linesGet(curSplice[0] + curSplice[1]) || '';
860+
curSplice[sline] = curSplice[sline].substring(0, curCol) + remaining;
861+
curSplice[1] += remaining ? 1 : 0;
859862
}
860863
} else {
864+
// nothing that is removed is in splice
865+
// implies curCol === 0
861866
removed = nextKLinesText(L);
862867
curSplice[1] += L;
863868
}

0 commit comments

Comments
 (0)