From 32a332fd3f79299af9f89f836a8d64e1ed4eb831 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Sat, 12 Feb 2011 13:13:35 +0100 Subject: [PATCH] fix desired column computation --- lib/ace/anchor.js | 10 +++++++++- lib/ace/selection.js | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/ace/anchor.js b/lib/ace/anchor.js index 1be42e22..f0a02183 100644 --- a/lib/ace/anchor.js +++ b/lib/ace/anchor.js @@ -138,9 +138,17 @@ var Anchor = exports.Anchor = function(doc, row, column) { if (this.row == pos.row && this.column == pos.column) return; + var old = { + row: this.row, + column: this.column + }; + this.row = pos.row; this.column = pos.column; - this._dispatchEvent("change"); + this._dispatchEvent("change", { + old: old, + value: pos + }); }; this.detach = function() { diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 12453a3e..a130228d 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -53,10 +53,12 @@ var Selection = function(session) { this.selectionAnchor = new Anchor(this.doc, 0, 0); var _self = this; - this.selectionLead.on("change", function() { + this.selectionLead.on("change", function(e) { _self._dispatchEvent("changeCursor"); if (!_self.$isEmpty) _self._dispatchEvent("changeSelection"); + if (e.old.row == e.value.row) + _self.$updateDesiredColumn(); }); this.selectionAnchor.on("change", function() { @@ -176,9 +178,7 @@ var Selection = function(session) { this.$updateDesiredColumn = function() { var cursor = this.getCursor(); - if (cursor) { - this.$desiredColumn = this.session.documentToScreenColumn(cursor.row, cursor.column); - } + this.$desiredColumn = this.session.documentToScreenColumn(cursor.row, cursor.column); }; this.$moveSelection = function(mover) {