fix goto line start to jump to toggle between

indentation end and column 0. Fixes #296
This commit is contained in:
Fabian Jakobs 2011-07-19 15:16:41 +02:00
commit 742f04b407
2 changed files with 53 additions and 12 deletions

View file

@ -318,25 +318,25 @@ var Selection = function(session) {
var screenRow = this.session.documentToScreenRow(row, column); var screenRow = this.session.documentToScreenRow(row, column);
// Determ the doc-position of the first character at the screen line. // Determ the doc-position of the first character at the screen line.
var firstColumnPosition = var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
this.session.screenToDocumentPosition(screenRow, 0);
// Determ the string "before" the cursor. // Determ the line
var beforeCursor = this.session.getDisplayLine( var beforeCursor = this.session.getDisplayLine(
row, column, row, null,
firstColumnPosition.row, firstColumnPosition.column); firstColumnPosition.row, firstColumnPosition.column
);
//
var leadingSpace = beforeCursor.match(/^\s*/); var leadingSpace = beforeCursor.match(/^\s*/);
if (leadingSpace[0].length == 0 if (leadingSpace[0].length == column) {
|| leadingSpace[0].length >= column - firstColumnPosition.column)
{
this.moveCursorTo( this.moveCursorTo(
firstColumnPosition.row, firstColumnPosition.column); firstColumnPosition.row, firstColumnPosition.column
} else { );
}
else {
this.moveCursorTo( this.moveCursorTo(
firstColumnPosition.row, firstColumnPosition.row,
firstColumnPosition.column + leadingSpace[0].length); firstColumnPosition.column + leadingSpace[0].length
);
} }
}; };

View file

@ -327,6 +327,47 @@ module.exports = {
// Move behind || // Move behind ||
selection.moveCursorWordLeft(); selection.moveCursorWordLeft();
assert.position(selection.getCursor(), 0, 0); 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);
} }
}; };