From 742f04b4079b9ab7df5cffed7a942bc934cb293a Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Tue, 19 Jul 2011 15:16:41 +0200 Subject: [PATCH] fix goto line start to jump to toggle between indentation end and column 0. Fixes #296 --- lib/ace/selection.js | 24 +++++++++++------------ lib/ace/selection_test.js | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/lib/ace/selection.js b/lib/ace/selection.js index e9d1d12b..4318d0e7 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -318,25 +318,25 @@ var Selection = function(session) { var screenRow = this.session.documentToScreenRow(row, column); // Determ the doc-position of the first character at the screen line. - var firstColumnPosition = - this.session.screenToDocumentPosition(screenRow, 0); + var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0); - // Determ the string "before" the cursor. + // Determ the line var beforeCursor = this.session.getDisplayLine( - row, column, - firstColumnPosition.row, firstColumnPosition.column); + row, null, + firstColumnPosition.row, firstColumnPosition.column + ); - // var leadingSpace = beforeCursor.match(/^\s*/); - if (leadingSpace[0].length == 0 - || leadingSpace[0].length >= column - firstColumnPosition.column) - { + if (leadingSpace[0].length == column) { this.moveCursorTo( - firstColumnPosition.row, firstColumnPosition.column); - } else { + firstColumnPosition.row, firstColumnPosition.column + ); + } + else { this.moveCursorTo( firstColumnPosition.row, - firstColumnPosition.column + leadingSpace[0].length); + firstColumnPosition.column + leadingSpace[0].length + ); } }; diff --git a/lib/ace/selection_test.js b/lib/ace/selection_test.js index ce13a213..3ed1d99a 100644 --- a/lib/ace/selection_test.js +++ b/lib/ace/selection_test.js @@ -327,6 +327,47 @@ module.exports = { // Move behind || selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 0); + }, + + "test: move cursor to line start should move cursor to end of the indentation first": function() { + var session = new EditSession("12\n Juhu\n12"); + var selection = session.getSelection(); + + selection.moveCursorTo(1, 6); + selection.moveCursorLineStart(); + + assert.position(selection.getCursor(), 1, 4); + }, + + "test: move cursor to line start when the cursor is at the end of the indentation should move cursor to column 0": function() { + var session = new EditSession("12\n Juhu\n12"); + var selection = session.getSelection(); + + selection.moveCursorTo(1, 4); + selection.moveCursorLineStart(); + + assert.position(selection.getCursor(), 1, 0); + }, + + "test: move cursor to line start when the cursor is at column 0 should move cursor to the end of the indentation": function() { + var session = new EditSession("12\n Juhu\n12"); + var selection = session.getSelection(); + + selection.moveCursorTo(1, 0); + selection.moveCursorLineStart(); + + assert.position(selection.getCursor(), 1, 4); + }, + + // Eclipse style + "test: move cursor to line start when the cursor is before the initial indentation should move cursor to the end of the indentation": function() { + var session = new EditSession("12\n Juhu\n12"); + var selection = session.getSelection(); + + selection.moveCursorTo(1, 2); + selection.moveCursorLineStart(); + + assert.position(selection.getCursor(), 1, 4); } };