ctrl-left/right must stop at both word start and end

This commit is contained in:
nightwing 2012-04-19 19:29:53 +04:00
commit 09de46063d

View file

@ -371,7 +371,7 @@ var Selection = function(session) {
this.moveCursorTo(0, 0);
};
this.moveCursorWordRight = function() {
this.moveCursorLongWordRight = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
var line = this.doc.getLine(row);
@ -413,7 +413,7 @@ var Selection = function(session) {
this.moveCursorTo(row, column);
};
this.moveCursorWordLeft = function() {
this.moveCursorLongWordLeft = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
@ -459,6 +459,87 @@ var Selection = function(session) {
this.moveCursorTo(row, column);
};
this.moveCursorShortWordRight = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
var line = this.doc.getLine(row);
var rightOfCursor = line.substring(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.end.row, fold.end.column);
return;
} else if (column == line.length) {
this.moveCursorRight();
return;
}
else if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
column += this.session.nonTokenRe.lastIndex;
this.session.nonTokenRe.lastIndex = 0;
}
else if (match = this.session.tokenRe.exec(rightOfCursor)) {
column += this.session.tokenRe.lastIndex;
this.session.tokenRe.lastIndex = 0;
}
this.moveCursorTo(row, column);
};
this.moveCursorShortWordLeft = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
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;
}
var str = this.session.getFoldStringAt(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;
}
else if (match = this.session.tokenRe.exec(leftOfCursor)) {
column -= this.session.tokenRe.lastIndex;
this.session.tokenRe.lastIndex = 0;
}
this.moveCursorTo(row, column);
};
this.moveCursorWordRight = function() {
if (this.session.$selectLongWords)
this.moveCursorLongWordRight();
else
this.moveCursorShortWordRight();
};
this.moveCursorWordLeft = function() {
if (this.session.$selectLongWords)
this.moveCursorLongWordLeft();
else
this.moveCursorShortWordLeft();
};
this.moveCursorBy = function(rows, chars) {
var screenPos = this.session.documentToScreenPosition(
this.selectionLead.row,