Add documentation for EditSesion.getFoldAt and change meaning of side.
This commit is contained in:
parent
af6dcc2253
commit
b6772e8ef2
2 changed files with 14 additions and 9 deletions
|
|
@ -1310,7 +1310,7 @@ var EditSession = function(text, mode) {
|
||||||
foldLine = null, lastFoldLine = null;
|
foldLine = null, lastFoldLine = null;
|
||||||
|
|
||||||
// Clamp the docRow position in case it's inside of a folded block.
|
// Clamp the docRow position in case it's inside of a folded block.
|
||||||
fold = this.getFoldAt(docRow, docColumn, -1);
|
fold = this.getFoldAt(docRow, docColumn, 1);
|
||||||
if (fold) {
|
if (fold) {
|
||||||
docRow = fold.start.row;
|
docRow = fold.start.row;
|
||||||
docColumn = fold.start.column;
|
docColumn = fold.start.column;
|
||||||
|
|
@ -1677,6 +1677,11 @@ var EditSession = function(text, mode) {
|
||||||
return this.range + "";
|
return this.range + "";
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks up a fold at a given row/column. Possible values for side:
|
||||||
|
* -1: ignore a fold if fold.start = row/column
|
||||||
|
* +1: ignore a fold if fold.end = row/column
|
||||||
|
*/
|
||||||
this.getFoldAt = function(row, column, side) {
|
this.getFoldAt = function(row, column, side) {
|
||||||
var foldLine = this.getFoldLine(row);
|
var foldLine = this.getFoldLine(row);
|
||||||
if (foldLine) {
|
if (foldLine) {
|
||||||
|
|
@ -1686,10 +1691,10 @@ var EditSession = function(text, mode) {
|
||||||
for (var i = 0; i < folds.length; i++) {
|
for (var i = 0; i < folds.length; i++) {
|
||||||
fold = folds[i];
|
fold = folds[i];
|
||||||
if (fold.range.contains(row, column)) {
|
if (fold.range.contains(row, column)) {
|
||||||
if (side == -1 && fold.range.isEnd(row, column)) {
|
if (side == 1 && fold.range.isEnd(row, column)) {
|
||||||
return null;
|
continue;
|
||||||
} else if (side == 1 && fold.range.isStart(row, column)) {
|
} else if (side == -1 && fold.range.isStart(row, column)) {
|
||||||
return null
|
continue;
|
||||||
}
|
}
|
||||||
return fold;
|
return fold;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@ var Selection = function(session) {
|
||||||
var cursor = this.selectionLead.getPosition(),
|
var cursor = this.selectionLead.getPosition(),
|
||||||
fold;
|
fold;
|
||||||
|
|
||||||
if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
|
if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
|
||||||
this.moveCursorTo(fold.start.row, fold.start.column);
|
this.moveCursorTo(fold.start.row, fold.start.column);
|
||||||
} else if (cursor.column == 0) {
|
} else if (cursor.column == 0) {
|
||||||
// cursor is a line (start
|
// cursor is a line (start
|
||||||
|
|
@ -285,7 +285,7 @@ var Selection = function(session) {
|
||||||
this.moveCursorRight = function() {
|
this.moveCursorRight = function() {
|
||||||
var cursor = this.selectionLead.getPosition(),
|
var cursor = this.selectionLead.getPosition(),
|
||||||
fold;
|
fold;
|
||||||
if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
|
if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
|
||||||
this.moveCursorTo(fold.end.row, fold.end.column);
|
this.moveCursorTo(fold.end.row, fold.end.column);
|
||||||
} else if (this.selectionLead.column == this.doc.getLine(this.selectionLead.row).length) {
|
} else if (this.selectionLead.column == this.doc.getLine(this.selectionLead.row).length) {
|
||||||
if (this.selectionLead.row < this.doc.getLength() - 1) {
|
if (this.selectionLead.row < this.doc.getLength() - 1) {
|
||||||
|
|
@ -348,7 +348,7 @@ var Selection = function(session) {
|
||||||
this.session.tokenRe.lastIndex = 0;
|
this.session.tokenRe.lastIndex = 0;
|
||||||
|
|
||||||
var fold;
|
var fold;
|
||||||
if (fold = this.session.getFoldAt(row, column, -1)) {
|
if (fold = this.session.getFoldAt(row, column, 1)) {
|
||||||
this.moveCursorTo(fold.end.row, fold.end.column);
|
this.moveCursorTo(fold.end.row, fold.end.column);
|
||||||
return;
|
return;
|
||||||
} else if (column == line.length) {
|
} else if (column == line.length) {
|
||||||
|
|
@ -372,7 +372,7 @@ var Selection = function(session) {
|
||||||
var column = this.selectionLead.column;
|
var column = this.selectionLead.column;
|
||||||
|
|
||||||
var fold;
|
var fold;
|
||||||
if (fold = this.session.getFoldAt(row, column, 1)) {
|
if (fold = this.session.getFoldAt(row, column, -1)) {
|
||||||
this.moveCursorTo(fold.start.row, fold.start.column);
|
this.moveCursorTo(fold.start.row, fold.start.column);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue