Get move(Word)Right/left working with folds
This commit is contained in:
parent
88f55c958a
commit
8c63cd7ff5
2 changed files with 121 additions and 10 deletions
|
|
@ -262,8 +262,12 @@ var Selection = function(session) {
|
|||
};
|
||||
|
||||
this.moveCursorLeft = function() {
|
||||
var cursor = this.selectionLead.getPosition();
|
||||
if (cursor.column == 0) {
|
||||
var cursor = this.selectionLead.getPosition(),
|
||||
fold;
|
||||
|
||||
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
|
||||
if (cursor.row > 0) {
|
||||
this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
|
||||
|
|
@ -279,7 +283,11 @@ var Selection = function(session) {
|
|||
};
|
||||
|
||||
this.moveCursorRight = function() {
|
||||
if (this.selectionLead.column == this.doc.getLine(this.selectionLead.row).length) {
|
||||
var cursor = this.selectionLead.getPosition(),
|
||||
fold;
|
||||
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) {
|
||||
this.moveCursorTo(this.selectionLead.row + 1, 0);
|
||||
}
|
||||
|
|
@ -339,7 +347,11 @@ var Selection = function(session) {
|
|||
this.session.nonTokenRe.lastIndex = 0;
|
||||
this.session.tokenRe.lastIndex = 0;
|
||||
|
||||
if (column == line.length) {
|
||||
var fold;
|
||||
if (fold = this.session.getFoldAt(row, column, 1)) {
|
||||
this.moveCursorTo(fold.end.row, fold.end.column);
|
||||
return;
|
||||
} else if (column == line.length) {
|
||||
this.moveCursorRight();
|
||||
return;
|
||||
}
|
||||
|
|
@ -358,18 +370,33 @@ var Selection = function(session) {
|
|||
this.moveCursorWordLeft = function() {
|
||||
var row = this.selectionLead.row;
|
||||
var column = this.selectionLead.column;
|
||||
var line = this.doc.getLine(row);
|
||||
var leftOfCursor = lang.stringReverse(line.substring(0, column));
|
||||
|
||||
var match;
|
||||
this.session.nonTokenRe.lastIndex = 0;
|
||||
this.session.tokenRe.lastIndex = 0;
|
||||
var fold;
|
||||
if (fold = this.session.getFoldAt(row, column, -1)) {
|
||||
this.moveCursorTo(fold.start.row, fold.start.column);
|
||||
return;
|
||||
}
|
||||
|
||||
if (column == 0) {
|
||||
this.moveCursorLeft();
|
||||
return;
|
||||
}
|
||||
else if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
|
||||
|
||||
var str = null;
|
||||
var foldLine = this.session.getFoldLine(row);
|
||||
if (foldLine) {
|
||||
str = foldLine.getStringAt(this.session, row, column, -1);
|
||||
}
|
||||
if (str == null) {
|
||||
str = this.doc.getLine(row).substring(0, column)
|
||||
}
|
||||
var leftOfCursor = lang.stringReverse(str);
|
||||
|
||||
var match;
|
||||
this.session.nonTokenRe.lastIndex = 0;
|
||||
this.session.tokenRe.lastIndex = 0;
|
||||
|
||||
if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
|
||||
column -= this.session.nonTokenRe.lastIndex;
|
||||
this.session.nonTokenRe.lastIndex = 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue