Fix move to first/last character in line if in wrap mode. Fixes some other bugs on the way and add some simple unit tests.
This commit is contained in:
parent
40472b71fc
commit
28ea247f17
8 changed files with 171 additions and 51 deletions
|
|
@ -170,7 +170,7 @@ var Selection = function(doc) {
|
|||
this.$updateDesiredColumn = function() {
|
||||
var cursor = this.getCursor();
|
||||
if (cursor) {
|
||||
this.$desiredColumn = this.doc.documentToScreenPosition(cursor.row, cursor.column).column;
|
||||
this.$desiredColumn = this.doc.documentToScreenColumn(cursor.row, cursor.column);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -311,19 +311,27 @@ var Selection = function(doc) {
|
|||
this.moveCursorLineStart = function() {
|
||||
var row = this.selectionLead.row;
|
||||
var column = this.selectionLead.column;
|
||||
var beforeCursor = this.doc.getLine(row).slice(0, column);
|
||||
var screenRow = this.doc.documentToScreenRow(row, column);
|
||||
var firstRowColumn = this.doc.getScreenFirstRowColumn(screenRow);
|
||||
var beforeCursor = this.doc.getLine(row).slice(firstRowColumn, column);
|
||||
var leadingSpace = beforeCursor.match(/^\s*/);
|
||||
if (leadingSpace[0].length == 0)
|
||||
this.moveCursorTo(row, this.doc.getLine(row).match(/^\s*/)[0].length);
|
||||
else if (leadingSpace[0].length >= column)
|
||||
this.moveCursorTo(row, 0);
|
||||
else
|
||||
this.moveCursorTo(row, leadingSpace[0].length);
|
||||
if (leadingSpace[0].length == 0) {
|
||||
var lastRowColumn = this.doc.getDocumentLastRowColumn(row, column);
|
||||
leadingSpace = this.doc.getLine(row).
|
||||
substring(firstRowColumn, lastRowColumn).
|
||||
match(/^\s*/);
|
||||
this.moveCursorTo(row, firstRowColumn + leadingSpace[0].length);
|
||||
} else if (leadingSpace[0].length >= column) {
|
||||
this.moveCursorTo(row, firstRowColumn);
|
||||
} else {
|
||||
this.moveCursorTo(row, firstRowColumn + leadingSpace[0].length);
|
||||
}
|
||||
};
|
||||
|
||||
this.moveCursorLineEnd = function() {
|
||||
this.moveCursorTo(this.selectionLead.row,
|
||||
this.doc.getLine(this.selectionLead.row).length);
|
||||
var selLead = this.selectionLead;
|
||||
this.moveCursorTo(selLead.row,
|
||||
this.doc.getDocumentLastRowColumn(selLead.row, selLead.column));
|
||||
};
|
||||
|
||||
this.moveCursorFileEnd = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue