diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 1e7da684..1c2f2f72 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -233,11 +233,11 @@ var Editor =function(renderer, doc) { this.renderer.updateLines(rows.first, rows.last); }; - this.onCursorChange = function() { + this.onCursorChange = function(e) { this.$highlightBrackets(); this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite); - if (!this.$blockScrolling) { + if (!this.$blockScrolling && (!e || !e.blockScrolling)) { this.renderer.scrollCursorIntoView(); } this.$updateHighlightActiveLine(); @@ -256,7 +256,7 @@ var Editor =function(renderer, doc) { } }; - this.onSelectionChange = function() { + this.onSelectionChange = function(e) { if (this.$selectionMarker) { this.renderer.removeMarker(this.$selectionMarker); } @@ -268,7 +268,7 @@ var Editor =function(renderer, doc) { this.$selectionMarker = this.renderer.addMarker(range, "ace_selection", style); } - this.onCursorChange(); + this.onCursorChange(e); }; this.onDocumentChangeBreakpoint = function() { diff --git a/lib/ace/selection.js b/lib/ace/selection.js index eb326c97..7639fcc0 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -150,9 +150,16 @@ var Selection = function(doc) { var lastRow = this.doc.getLength() - 1; this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length); - this.$moveSelection(function() { - this.moveCursorTo(0, 0); - }); + if (!this.selectionAnchor) { + this.selectionAnchor = this.$clone(this.selectionLead); + } + + var cursor = {row:0, column:0}; + // only dispatch change if the cursor actually changed + if (cursor.row !== this.selectionLead.row || cursor.column !== this.selectionLead.column) { + this.selectionLead = cursor; + this._dispatchEvent("changeSelection", {blockScrolling: true}); + } }; this.setSelectionRange = function(range, reverse) {