Merge pull request #1902 from pjhuck/master

fix for anchor & insertRight behavior
This commit is contained in:
Harutyun Amirjanyan 2014-04-10 14:35:45 +05:00
commit 831f6c9336
2 changed files with 39 additions and 1 deletions

View file

@ -131,7 +131,10 @@ var Anchor = exports.Anchor = function(doc, row, column) {
row += end.row - start.row;
}
} else if (delta.action === "insertLines") {
if (start.row <= row) {
if (start.row === row && column === 0 && this.$insertRight) {
// do nothing
}
else if (start.row <= row) {
row += end.row - start.row;
}
} else if (delta.action === "removeText") {

View file

@ -57,6 +57,15 @@ module.exports = {
doc.insert({row: 1, column: 1}, "123");
assert.position(anchor.getPosition(), 1, 7);
},
"test insert text at anchor should not move anchor when insertRight is true": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
anchor.$insertRight = true;
doc.insert({row: 1, column: 4}, "123");
assert.position(anchor.getPosition(), 1, 4);
},
"test insert lines before cursor should move anchor row": function() {
var doc = new Document("juhu\nkinners");
@ -65,6 +74,32 @@ module.exports = {
doc.insertLines(1, ["123", "456"]);
assert.position(anchor.getPosition(), 3, 4);
},
"test insert lines at anchor position should move anchor down": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 0);
doc.insertLines(1, ["line"]);
assert.position(anchor.getPosition(), 2, 0);
},
"test insert lines at anchor position should not move anchor down when insertRight is true and column is 0": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 0);
anchor.$insertRight = true;
doc.insertLines(1, ["line"]);
assert.position(anchor.getPosition(), 1, 0);
},
"test insert lines at anchor row should move anchor down when column > 0": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 2);
anchor.$insertRight = true;
doc.insertLines(1, ["line"]);
assert.position(anchor.getPosition(), 2, 2);
},
"test insert new line before cursor should move anchor column": function() {
var doc = new Document("juhu\nkinners");