Add documentation for EditSesion.getFoldAt and change meaning of side.

This commit is contained in:
Julian Viereck 2011-04-26 00:12:23 +02:00
commit b6772e8ef2
2 changed files with 14 additions and 9 deletions

View file

@ -1310,7 +1310,7 @@ var EditSession = function(text, mode) {
foldLine = null, lastFoldLine = null;
// 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) {
docRow = fold.start.row;
docColumn = fold.start.column;
@ -1677,6 +1677,11 @@ var EditSession = function(text, mode) {
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) {
var foldLine = this.getFoldLine(row);
if (foldLine) {
@ -1686,10 +1691,10 @@ var EditSession = function(text, mode) {
for (var i = 0; i < folds.length; i++) {
fold = folds[i];
if (fold.range.contains(row, column)) {
if (side == -1 && fold.range.isEnd(row, column)) {
return null;
} else if (side == 1 && fold.range.isStart(row, column)) {
return null
if (side == 1 && fold.range.isEnd(row, column)) {
continue;
} else if (side == -1 && fold.range.isStart(row, column)) {
continue;
}
return fold;
}

View file

@ -265,7 +265,7 @@ var Selection = function(session) {
var cursor = this.selectionLead.getPosition(),
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);
} else if (cursor.column == 0) {
// cursor is a line (start
@ -285,7 +285,7 @@ var Selection = function(session) {
this.moveCursorRight = function() {
var cursor = this.selectionLead.getPosition(),
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);
} else if (this.selectionLead.column == this.doc.getLine(this.selectionLead.row).length) {
if (this.selectionLead.row < this.doc.getLength() - 1) {
@ -348,7 +348,7 @@ var Selection = function(session) {
this.session.tokenRe.lastIndex = 0;
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);
return;
} else if (column == line.length) {
@ -372,7 +372,7 @@ var Selection = function(session) {
var column = this.selectionLead.column;
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);
return;
}