Skip to content

Commit

Permalink
textLinesMutator: Fix insertions at the end of lines
Browse files Browse the repository at this point in the history
The new insertions are directly pushed to curSplice now instead of
incorporating an undefined line into the splice.
  • Loading branch information
webzwo0i authored and rhansen committed Nov 23, 2021
1 parent f95e8a5 commit 0a6d02c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/static/js/Changeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,11 +979,17 @@ class TextLinesMutator {
this._curSplice.push(...newLines);
this._curLine += newLines.length;
}
} else {
} else if (!this.hasMore()) {
// There are no additional lines. Although the line is put into splice, curLine is not
// increased because there may be more chars in the line (newline is not reached).
// increased because there may be more chars in the line (newline is not reached). We are
// inserting at the end of lines. curCol is 0 as curLine is not in splice.
this._curSplice.push(text);
this._curCol += text.length;
} else {
// insert text after curCol
const sline = this._putCurLineInSplice();
if (!this._curSplice[sline]) {
// TODO should never happen now
const err = new Error(
'curSplice[sline] not populated, actual curSplice contents is ' +
`${JSON.stringify(this._curSplice)}. Possibly related to ` +
Expand Down

0 comments on commit 0a6d02c

Please sign in to comment.