Merge pull request #2649 from xavidotron/develop

When using setText(), replace the entire existing text of the pad.
This commit is contained in:
John McLear 2015-05-06 16:37:07 +01:00
commit ee0368fd0f
4 changed files with 10 additions and 10 deletions

View File

@ -290,7 +290,7 @@ Pad.prototype.setText = function setText(newText) {
var oldText = this.text(); var oldText = this.text();
//create the changeset //create the changeset
var changeset = Changeset.makeSplice(oldText, 0, oldText.length-1, newText); var changeset = Changeset.makeSplice(oldText, 0, oldText.length, newText);
//append the changeset //append the changeset
this.appendRevision(changeset); this.appendRevision(changeset);

View File

@ -89,7 +89,7 @@ function setPadHTML(pad, html, callback)
// the changeset is ready! // the changeset is ready!
var theChangeset = builder.toString(); var theChangeset = builder.toString();
apiLogger.debug('The changeset: ' + theChangeset); apiLogger.debug('The changeset: ' + theChangeset);
pad.setText(""); pad.setText("\n");
pad.appendRevision(theChangeset); pad.appendRevision(theChangeset);
callback(null); callback(null);
} }

View File

@ -260,13 +260,13 @@ exports.checkRep = function (cs) {
break; break;
case '-': case '-':
oldPos += o.chars; oldPos += o.chars;
exports.assert(oldPos < oldLen, oldPos, " >= ", oldLen, " in ", cs); exports.assert(oldPos <= oldLen, oldPos, " > ", oldLen, " in ", cs);
break; break;
case '+': case '+':
{ {
calcNewLen += o.chars; calcNewLen += o.chars;
numInserted += o.chars; numInserted += o.chars;
exports.assert(calcNewLen < newLen, calcNewLen, " >= ", newLen, " in ", cs); exports.assert(calcNewLen <= newLen, calcNewLen, " > ", newLen, " in ", cs);
break; break;
} }
} }
@ -1408,8 +1408,8 @@ exports.makeSplice = function (oldFullText, spliceStart, numRemoved, newText, op
if (spliceStart >= oldLen) { if (spliceStart >= oldLen) {
spliceStart = oldLen - 1; spliceStart = oldLen - 1;
} }
if (numRemoved > oldFullText.length - spliceStart - 1) { if (numRemoved > oldFullText.length - spliceStart) {
numRemoved = oldFullText.length - spliceStart - 1; numRemoved = oldFullText.length - spliceStart;
} }
var oldText = oldFullText.substring(spliceStart, spliceStart + numRemoved); var oldText = oldFullText.substring(spliceStart, spliceStart + numRemoved);
var newLen = oldLen + newText.length - oldText.length; var newLen = oldLen + newText.length - oldText.length;

View File

@ -210,7 +210,7 @@ describe('getText', function(){
it('gets the Pad text', function(done) { it('gets the Pad text', function(done) {
api.get(endPoint('getText')+"&padID="+testPadId) api.get(endPoint('getText')+"&padID="+testPadId)
.expect(function(res){ .expect(function(res){
if(res.body.data.text !== "testTextTwo\n") throw new Error("Setting Text") if(res.body.data.text !== "testTextTwo") throw new Error("Setting Text")
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done) .expect(200, done)
@ -386,7 +386,7 @@ describe('getText', function(){
api.get(endPoint('getText')+"&padID="+testPadId) api.get(endPoint('getText')+"&padID="+testPadId)
.expect(function(res){ .expect(function(res){
if(res.body.code !== 0) throw new Error("Pad Get Text failed") if(res.body.code !== 0) throw new Error("Pad Get Text failed")
if(res.body.data.text !== text+"\n") throw new Error("Pad Text not set properly"); if(res.body.data.text !== text) throw new Error("Pad Text not set properly");
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done) .expect(200, done)
@ -419,7 +419,7 @@ describe('getText', function(){
it('Gets text on a pad Id', function(done) { it('Gets text on a pad Id', function(done) {
api.get(endPoint('getText')+"&padID="+newPadId) api.get(endPoint('getText')+"&padID="+newPadId)
.expect(function(res){ .expect(function(res){
if(res.body.data.text !== text+"\n") throw new Error("Pad Get Text failed") if(res.body.data.text !== text) throw new Error("Pad Get Text failed")
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done) .expect(200, done)
@ -441,7 +441,7 @@ describe('getText', function(){
it('Gets text on a pad Id', function(done) { it('Gets text on a pad Id', function(done) {
api.get(endPoint('getText')+"&padID="+testPadId) api.get(endPoint('getText')+"&padID="+testPadId)
.expect(function(res){ .expect(function(res){
if(res.body.data.text !== text+"\n") throw new Error("Pad Get Text failed") if(res.body.data.text !== text) throw new Error("Pad Get Text failed")
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done) .expect(200, done)