Make Selection.moveCursorFirstLine work again. Fixing some bugs on the way.

This commit is contained in:
Julian Viereck 2011-04-28 18:21:36 +02:00
commit 5573252193
5 changed files with 80 additions and 46 deletions

View file

@ -316,18 +316,27 @@ var Selection = function(session) {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
var screenRow = this.session.documentToScreenRow(row, column);
var firstRowColumn = this.session.screenToDocumentColumn(screenRow, 0)
var beforeCursor = this.doc.getLine(row).slice(firstRowColumn, column);
// Determ the doc-position of the first character at the screen line.
var firstColumnPosition =
this.session.screenToDocumentPosition(screenRow, 0);
// Determ the string "before" the cursor.
var beforeCursor = this.session.getDisplayLine(
row, column,
firstColumnPosition.row, firstColumnPosition.column);
//
var leadingSpace = beforeCursor.match(/^\s*/);
if (leadingSpace[0].length == 0) {
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);
if (leadingSpace[0].length == 0
|| leadingSpace[0].length >= column - firstColumnPosition.column)
{
this.moveCursorTo(
firstColumnPosition.row, firstColumnPosition.column);
} else {
this.moveCursorTo(row, firstRowColumn + leadingSpace[0].length);
this.moveCursorTo(
firstColumnPosition.row,
firstColumnPosition.column + leadingSpace[0].length);
}
};