diff --git a/lib/ace/selection.js b/lib/ace/selection.js index a0b60301..b630d763 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -390,15 +390,19 @@ var Selection = function(doc) { this.moveCursorBy = function(rows, chars) { if (this.doc.getUseWrapMode()) { - var pos = this.doc.documentToScreenPosition( + var screenPos = this.doc.documentToScreenPosition( this.selectionLead.row, this.selectionLead.column); - pos = this.doc.screenToDocumentPosition( - pos.row + rows, (this.$desiredColumn || pos.column)); - this.moveCursorTo(pos.row, pos.column + chars, chars == 0); + var screenCol = + (chars == 0 && this.$desiredColumn) || screenPos.column; + + var docPos = this.doc.screenToDocumentPosition( + screenPos.row + rows, screenCol); + this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0); } else { - this.moveCursorTo(this.selectionLead.row + rows, - (this.$desiredColumn || this.selectionLead.column) + chars, - chars == 0); + var docColumn = + (chars == 0 && this.$desiredColumn) || this.selectionLead.column; + this.moveCursorTo( + this.selectionLead.row + rows, docColumn + chars, chars == 0); } };