only fire change events if selection/cursor really changes

This commit is contained in:
Fabian Jakobs 2010-04-22 19:02:38 +02:00
commit 39433d0733
4 changed files with 52 additions and 14 deletions

View file

@ -21,7 +21,7 @@ var NavigationTest = TestCase("NavigationTest",
var doc = this.createTextDocument(200, 10);
var editor = new ace.Editor(new MockRenderer(), doc);
editor.scrollToRow(editor.getLastVisibleRow() + 20);
editor.moveCursorTo(editor.getLastVisibleRow() + 20);
editor.navigateFileStart();
assertEquals(0, editor.getFirstVisibleRow());

View file

@ -216,5 +216,35 @@ var SelectionTest = TestCase("SelectionTest",
var range = selection.getRange();
assertPosition(0, 4, range.start);
assertPosition(0, 6, range.end);
},
"test: moving cursor should fire a 'changeCursor' event" : function() {
var doc = new ace.Document("Juhu Kinners");
var selection = doc.getSelection();
selection.moveCursorTo(0, 5);
var called = false;
selection.addEventListener("changeCursor", function() {
called = true;
});
selection.moveCursorTo(0, 6);
assertTrue(called);
},
"test: calling setCursor with the same position should not fire an event": function() {
var doc = new ace.Document("Juhu Kinners");
var selection = doc.getSelection();
selection.moveCursorTo(0, 5);
var called = false;
selection.addEventListener("changeCursor", function() {
called = true;
});
selection.moveCursorTo(0, 5);
assertFalse(called);
}
});