Add support for folded lines in Selection.selectLine

This commit is contained in:
Julian Viereck 2011-04-28 16:11:40 +02:00
commit 61fc8d04c4
3 changed files with 40 additions and 6 deletions

View file

@ -1268,7 +1268,12 @@ var EditSession = function(text, mode) {
this.getDocumentLastRowColumn = function(docRow, docColumn) {
var screenRow = this.documentToScreenRow(docRow, docColumn);
return this.getScreenLastRowColumn(screenRow);
}
};
this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
var screenRow = this.documentToScreenRow(docRow, docColumn);
return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
};
this.getRowSplitData = function(row) {
if (!this.$useWrapMode) {

View file

@ -371,7 +371,22 @@ function Folding() {
}
}.bind(this), endRow, endColumn);
return textLine;
}
};
this.getDisplayLine = function(row, endColumn) {
var foldLine = this.getFoldLine(row);
if (!foldLine) {
if (endColumn == null) {
return this.doc.$lines[row];
} else {
var line = this.doc.$lines[row];
return line.substring(endColumn);
}
} else {
return this.getFoldDisplayLine(foldLine, row, endColumn);
}
};
}
exports.Folding = Folding;

View file

@ -247,9 +247,19 @@ var Selection = function(session) {
};
this.selectLine = function() {
this.setSelectionAnchor(this.selectionLead.row, 0);
var rowStart = this.selectionLead.row;
var rowEnd;
var foldLine = this.session.getFoldLine(rowStart);
if (foldLine) {
rowStart = foldLine.start.row;
rowEnd = foldLine.end.row;
} else {
rowEnd = rowStart;
}
this.setSelectionAnchor(rowStart, 0);
this.$moveSelection(function() {
this.moveCursorTo(this.selectionLead.row + 1, 0);
this.moveCursorTo(rowEnd + 1, 0);
});
};
@ -310,7 +320,6 @@ var Selection = function(session) {
var beforeCursor = this.doc.getLine(row).slice(firstRowColumn, column);
var leadingSpace = beforeCursor.match(/^\s*/);
if (leadingSpace[0].length == 0) {
var lastRowColumn = this.session.getDocumentLastRowColumn(row, column);
leadingSpace = this.doc.getLine(row).
substring(firstRowColumn, lastRowColumn).
match(/^\s*/);
@ -324,7 +333,12 @@ var Selection = function(session) {
this.moveCursorLineEnd = function() {
var lead = this.selectionLead;
this.moveCursorTo(lead.row, this.session.getDocumentLastRowColumn(lead.row, lead.column));
var lastRowColumnPosition =
this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
this.moveCursorTo(
lastRowColumnPosition.row,
lastRowColumnPosition.column
);
};
this.moveCursorFileEnd = function() {