mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
Pad: Simplify setText
This commit is contained in:
parent
10e2b09b96
commit
a6bf7816ce
1 changed files with 4 additions and 14 deletions
|
@ -256,21 +256,11 @@ Pad.prototype.text = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
Pad.prototype.setText = async function (newText) {
|
Pad.prototype.setText = async function (newText) {
|
||||||
// clean the new text
|
|
||||||
newText = exports.cleanText(newText);
|
newText = exports.cleanText(newText);
|
||||||
|
if (!newText.endsWith('\n')) newText += '\n';
|
||||||
const oldText = this.text();
|
const orig = this.text();
|
||||||
|
if (newText === orig) return;
|
||||||
// create the changeset
|
const changeset = Changeset.makeSplice(orig, 0, orig.length, newText);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.appendRevision(changeset);
|
await this.appendRevision(changeset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue