From b1d0848701e358d1a9f2b99314a0bcd4478a9b63 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 13 Dec 2021 01:29:00 -0500 Subject: [PATCH] Pad: Improve readability of `appendText` --- src/node/db/Pad.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index 45f8ad6af..b7bbdb867 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -264,16 +264,16 @@ Pad.prototype.setText = async function (newText) { await this.appendRevision(changeset); }; +/** + * Appends text to the pad. + * + * @param {string} newText - Text to insert just BEFORE the pad's existing terminating newline. + */ Pad.prototype.appendText = async function (newText) { - // clean the new text newText = exports.cleanText(newText); - - const oldText = this.text(); - - // create the changeset - const changeset = Changeset.makeSplice(oldText, oldText.length, 0, newText); - - // append the changeset + const orig = this.text(); + assert(orig.endsWith('\n')); + const changeset = Changeset.makeSplice(orig, orig.length - 1, 0, newText); await this.appendRevision(changeset); };