Restore newline-adding to setText() if passed string does not end in '\n'.

Add a test for the ending-in-'\n' case and update tests for the other case.
This commit is contained in:
Xavid 2015-06-30 04:47:55 -04:00
parent d803ac128e
commit ad137fa4c8
2 changed files with 35 additions and 5 deletions

View file

@ -290,7 +290,14 @@ Pad.prototype.setText = function setText(newText) {
var oldText = this.text();
//create the changeset
var changeset = Changeset.makeSplice(oldText, 0, oldText.length, newText);
// We want to ensure the pad still ends with a \n, but otherwise keep
// getText() and setText() consistent.
var 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);
}
//append the changeset
this.appendRevision(changeset);