fix goto line start to jump to toggle between
indentation end and column 0. Fixes #296
This commit is contained in:
parent
4740580535
commit
742f04b407
2 changed files with 53 additions and 12 deletions
|
|
@ -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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue