From ce6c0aa84b5dfb6944cc81a0148b42266d3dfd7c Mon Sep 17 00:00:00 2001 From: Paul Huck Date: Wed, 9 Apr 2014 09:46:53 -0700 Subject: [PATCH] fix for anchor & insertRight behavior Do not move the anchor down when it is at column 0 and lines are inserted at that --- lib/ace/anchor.js | 5 ++++- lib/ace/anchor_test.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/ace/anchor.js b/lib/ace/anchor.js index 0f2e9571..4e330ef6 100644 --- a/lib/ace/anchor.js +++ b/lib/ace/anchor.js @@ -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") { diff --git a/lib/ace/anchor_test.js b/lib/ace/anchor_test.js index 2d7fcb63..b5c62941 100644 --- a/lib/ace/anchor_test.js +++ b/lib/ace/anchor_test.js @@ -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");