Make Selection.moveCursorFirstLine work again. Fixing some bugs on the way.
This commit is contained in:
parent
61fc8d04c4
commit
5573252193
5 changed files with 80 additions and 46 deletions
|
|
@ -1325,11 +1325,6 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
|
docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
|
||||||
|
|
||||||
if (foldLine) {
|
|
||||||
var position = foldLine.idxToPosition(docColumn);
|
|
||||||
return [position.row, position.column];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Need to do some clamping action here.
|
// Need to do some clamping action here.
|
||||||
if (this.$useWrapMode) {
|
if (this.$useWrapMode) {
|
||||||
column = splits[screenRow - row]
|
column = splits[screenRow - row]
|
||||||
|
|
@ -1343,6 +1338,11 @@ var EditSession = function(text, mode) {
|
||||||
docColumn = Math.min(docColumn, line.length);
|
docColumn = Math.min(docColumn, line.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (foldLine) {
|
||||||
|
var position = foldLine.idxToPosition(docColumn);
|
||||||
|
return [position.row, position.column];
|
||||||
|
}
|
||||||
|
|
||||||
return [docRow, docColumn, screenRow, row]
|
return [docRow, docColumn, screenRow, row]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ function FoldLine(foldData, folds) {
|
||||||
}
|
}
|
||||||
|
|
||||||
stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
|
stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
|
||||||
stop = !stop && callback(fold.placeholder, null, null, lastEnd);
|
stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
|
||||||
|
|
||||||
// If the user requested to stop the walk or endRow/endColumn is
|
// If the user requested to stop the walk or endRow/endColumn is
|
||||||
// inside of this fold (comp == 0), then end here.
|
// inside of this fold (comp == 0), then end here.
|
||||||
|
|
@ -267,6 +267,22 @@ function FoldLine(foldData, folds) {
|
||||||
column: this.end.column + idx
|
column: this.end.column + idx
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this.positionToIdx = function(pos) {
|
||||||
|
// var row = pos.row;
|
||||||
|
// var column = pos.column;
|
||||||
|
// var idx = 0;
|
||||||
|
//
|
||||||
|
// this.walk(function(placeholder, row, column, lastColumn) {
|
||||||
|
// if (placeholder
|
||||||
|
// var range = new Range(row, lastColumn, row, column);
|
||||||
|
// var cmp = range.compareEnd(row, column);
|
||||||
|
//
|
||||||
|
// if (cmp == 0) {
|
||||||
|
// idx +=
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
}).call(FoldLine.prototype);
|
}).call(FoldLine.prototype);
|
||||||
|
|
||||||
exports.FoldLine = FoldLine;
|
exports.FoldLine = FoldLine;
|
||||||
|
|
|
||||||
|
|
@ -350,41 +350,50 @@ function Folding() {
|
||||||
: docRow)
|
: docRow)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getFoldDisplayLine = function(foldLine, endRow, endColumn) {
|
this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
|
||||||
|
if (startRow == null) {
|
||||||
|
startRow = foldLine.start.row;
|
||||||
|
startColumn = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (endRow == null) {
|
if (endRow == null) {
|
||||||
endRow = foldLine.end.row;
|
endRow = foldLine.end.row;
|
||||||
endColumn = this.getLine(endRow).length;
|
endColumn = this.getLine(endRow).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the textline using the FoldLine walker.
|
// Build the textline using the FoldLine walker.
|
||||||
var line = "",
|
var line = "";
|
||||||
textLine = "";
|
var lines = this.doc.$lines;
|
||||||
|
var textLine = "";
|
||||||
|
|
||||||
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
|
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
|
||||||
|
if (row < startRow) {
|
||||||
|
return;
|
||||||
|
} else if (row == startRow) {
|
||||||
|
if (column < startColumn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastColumn = Math.max(startColumn, lastColumn);
|
||||||
|
}
|
||||||
if (placeholder) {
|
if (placeholder) {
|
||||||
textLine += placeholder;
|
textLine += placeholder;
|
||||||
} else {
|
} else {
|
||||||
if (isNewRow) {
|
textLine += lines[row].substring(lastColumn, column);
|
||||||
line = this.getLine(row);
|
|
||||||
}
|
|
||||||
textLine += line.substring(lastColumn, column);
|
|
||||||
}
|
}
|
||||||
}.bind(this), endRow, endColumn);
|
}.bind(this), endRow, endColumn);
|
||||||
return textLine;
|
return textLine;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getDisplayLine = function(row, endColumn) {
|
this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
|
||||||
var foldLine = this.getFoldLine(row);
|
var foldLine = this.getFoldLine(row);
|
||||||
|
|
||||||
if (!foldLine) {
|
if (!foldLine) {
|
||||||
if (endColumn == null) {
|
var line;
|
||||||
return this.doc.$lines[row];
|
line = this.doc.$lines[row];
|
||||||
} else {
|
return line.substring(startColumn || 0, endColumn || line.length);
|
||||||
var line = this.doc.$lines[row];
|
|
||||||
return line.substring(endColumn);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return this.getFoldDisplayLine(foldLine, row, endColumn);
|
return this.getFoldDisplayLine(
|
||||||
|
foldLine, row, endColumn, startRow, startColumn);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -316,18 +316,27 @@ var Selection = function(session) {
|
||||||
var row = this.selectionLead.row;
|
var row = this.selectionLead.row;
|
||||||
var column = this.selectionLead.column;
|
var column = this.selectionLead.column;
|
||||||
var screenRow = this.session.documentToScreenRow(row, 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*/);
|
var leadingSpace = beforeCursor.match(/^\s*/);
|
||||||
if (leadingSpace[0].length == 0) {
|
if (leadingSpace[0].length == 0
|
||||||
leadingSpace = this.doc.getLine(row).
|
|| leadingSpace[0].length >= column - firstColumnPosition.column)
|
||||||
substring(firstRowColumn, lastRowColumn).
|
{
|
||||||
match(/^\s*/);
|
this.moveCursorTo(
|
||||||
this.moveCursorTo(row, firstRowColumn + leadingSpace[0].length);
|
firstColumnPosition.row, firstColumnPosition.column);
|
||||||
} else if (leadingSpace[0].length >= column) {
|
|
||||||
this.moveCursorTo(row, firstRowColumn);
|
|
||||||
} else {
|
} else {
|
||||||
this.moveCursorTo(row, firstRowColumn + leadingSpace[0].length);
|
this.moveCursorTo(
|
||||||
|
firstColumnPosition.row,
|
||||||
|
firstColumnPosition.column + leadingSpace[0].length);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,21 +16,21 @@ var tests = [
|
||||||
// require("ace/editor_text_edit_test"),
|
// require("ace/editor_text_edit_test"),
|
||||||
// require("ace/document_test"),
|
// require("ace/document_test"),
|
||||||
require("ace/edit_session_test"),
|
require("ace/edit_session_test"),
|
||||||
// require("ace/test/event_emitter_test"),
|
// require("ace/test/event_emitter_test"),
|
||||||
// require("ace/range_test"),
|
// require("ace/range_test"),
|
||||||
// require("ace/search_test"),
|
// require("ace/search_test"),
|
||||||
// require("ace/selection_test"),
|
require("ace/selection_test"),
|
||||||
// require("ace/virtual_renderer_test"),
|
// require("ace/virtual_renderer_test"),
|
||||||
// require("ace/anchor_test"),
|
// require("ace/anchor_test"),
|
||||||
// require("ace/mode/css_test"),
|
// require("ace/mode/css_test"),
|
||||||
// require("ace/mode/css_tokenizer_test"),
|
// require("ace/mode/css_tokenizer_test"),
|
||||||
// require("ace/mode/html_test"),
|
// require("ace/mode/html_test"),
|
||||||
// require("ace/mode/html_tokenizer_test"),
|
// require("ace/mode/html_tokenizer_test"),
|
||||||
// require("ace/mode/javascript_test"),
|
// require("ace/mode/javascript_test"),
|
||||||
// require("ace/mode/javascript_tokenizer_test"),
|
// require("ace/mode/javascript_tokenizer_test"),
|
||||||
// require("ace/mode/text_test"),
|
// require("ace/mode/text_test"),
|
||||||
// require("ace/mode/xml_test"),
|
// require("ace/mode/xml_test"),
|
||||||
// require("ace/mode/xml_tokenizer_test")
|
// require("ace/mode/xml_tokenizer_test")
|
||||||
]
|
]
|
||||||
|
|
||||||
async.list(tests)
|
async.list(tests)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue