From af7b5d1a8966c9dc870b83f70c6365112cfa9b3e Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sat, 30 Oct 2021 23:42:15 +0200 Subject: [PATCH] textLinesMutator: Fix insertions at the end of `lines`. The new insertions are directly pushed to curSplice now instead of incorporating an undefined line into the splice. --- src/static/js/Changeset.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index ed132aa781d..cf2b565adee 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -930,12 +930,18 @@ exports.textLinesMutator = (lines) => { Array.prototype.push.apply(curSplice, newLines); curLine += newLines.length; } - } else { + } else if (!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) + // we are inserting at the end of lines. curCol is 0 as curLine is not in splice + curSplice.push(text); + curCol += text.length; + } else { + // insert text after curCol const sline = putCurLineInSplice(); if (!curSplice[sline]) { + // TODO should never happen now console.error('curSplice[sline] not populated, actual curSplice contents is ', curSplice, '. Possibly related to https://github.com/ether/etherpad-lite/issues/2802'); } curSplice[sline] = curSplice[sline].substring(0, curCol) + text +