From a6bf7816ced632b51461e9e75dd915e0d06d42f2 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 13 Dec 2021 01:21:40 -0500 Subject: [PATCH] Pad: Simplify `setText` --- src/node/db/Pad.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index abca75102..45f8ad6af 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -256,21 +256,11 @@ Pad.prototype.text = function () { }; Pad.prototype.setText = async function (newText) { - // clean the new text newText = exports.cleanText(newText); - - const oldText = this.text(); - - // create the changeset - // We want to ensure the pad still ends with a \n, but otherwise keep - // getText() and setText() consistent. - let changeset; - if (newText[newText.length - 1] === '\n') { - changeset = Changeset.makeSplice(oldText, 0, oldText.length, newText); - } else { - changeset = Changeset.makeSplice(oldText, 0, oldText.length - 1, newText); - } - + if (!newText.endsWith('\n')) newText += '\n'; + const orig = this.text(); + if (newText === orig) return; + const changeset = Changeset.makeSplice(orig, 0, orig.length, newText); await this.appendRevision(changeset); };