fix for anchor & insertRight behavior
Do not move the anchor down when it is at column 0 and lines are inserted at that
This commit is contained in:
parent
32cbb0ffa1
commit
ce6c0aa84b
2 changed files with 39 additions and 1 deletions
|
|
@ -131,7 +131,10 @@ var Anchor = exports.Anchor = function(doc, row, column) {
|
||||||
row += end.row - start.row;
|
row += end.row - start.row;
|
||||||
}
|
}
|
||||||
} else if (delta.action === "insertLines") {
|
} 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;
|
row += end.row - start.row;
|
||||||
}
|
}
|
||||||
} else if (delta.action === "removeText") {
|
} else if (delta.action === "removeText") {
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,15 @@ module.exports = {
|
||||||
assert.position(anchor.getPosition(), 1, 7);
|
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() {
|
"test insert lines before cursor should move anchor row": function() {
|
||||||
var doc = new Document("juhu\nkinners");
|
var doc = new Document("juhu\nkinners");
|
||||||
var anchor = new Anchor(doc, 1, 4);
|
var anchor = new Anchor(doc, 1, 4);
|
||||||
|
|
@ -66,6 +75,32 @@ module.exports = {
|
||||||
assert.position(anchor.getPosition(), 3, 4);
|
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() {
|
"test insert new line before cursor should move anchor column": function() {
|
||||||
var doc = new Document("juhu\nkinners");
|
var doc = new Document("juhu\nkinners");
|
||||||
var anchor = new Anchor(doc, 1, 4);
|
var anchor = new Anchor(doc, 1, 4);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue