moveByShortWords should stop at punctuation groups
This commit is contained in:
parent
341f52b809
commit
cc0919414f
1 changed files with 51 additions and 46 deletions
|
|
@ -470,34 +470,58 @@ var Selection = function(session) {
|
|||
this.moveCursorTo(row, column);
|
||||
};
|
||||
|
||||
this.$shortWordEndIndex = function(rightOfCursor) {
|
||||
var match, index = 0, ch;
|
||||
var whitespaceRe = /\s/;
|
||||
var tokenRe = this.session.tokenRe;
|
||||
|
||||
tokenRe.lastIndex = 0;
|
||||
if (match = this.session.tokenRe.exec(rightOfCursor)) {
|
||||
index = this.session.tokenRe.lastIndex;
|
||||
} else {
|
||||
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
|
||||
index ++;
|
||||
|
||||
if (index <= 1) {
|
||||
tokenRe.lastIndex = 0;
|
||||
while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
|
||||
tokenRe.lastIndex = 0;
|
||||
index ++;
|
||||
if (whitespaceRe.test(ch)) {
|
||||
if (index > 2) {
|
||||
index--
|
||||
break;
|
||||
} else {
|
||||
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
|
||||
index ++;
|
||||
if (index > 2)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tokenRe.lastIndex = 0;
|
||||
|
||||
return index;
|
||||
};
|
||||
|
||||
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 = this.session.getFoldAt(row, column, 1);
|
||||
if (fold)
|
||||
return this.moveCursorTo(fold.end.row, fold.end.column);
|
||||
|
||||
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;
|
||||
}
|
||||
if (column == line.length)
|
||||
return this.moveCursorRight();
|
||||
|
||||
this.moveCursorTo(row, column);
|
||||
var index = this.$shortWordEndIndex(rightOfCursor);
|
||||
|
||||
this.moveCursorTo(row, column + index);
|
||||
};
|
||||
|
||||
this.moveCursorShortWordLeft = function() {
|
||||
|
|
@ -505,36 +529,17 @@ var Selection = function(session) {
|
|||
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 (fold = this.session.getFoldAt(row, column, -1))
|
||||
return this.moveCursorTo(fold.start.row, fold.start.column);
|
||||
|
||||
if (column == 0) {
|
||||
this.moveCursorLeft();
|
||||
return;
|
||||
}
|
||||
if (column == 0)
|
||||
return this.moveCursorLeft();
|
||||
|
||||
var str = this.session.getFoldStringAt(row, column, -1);
|
||||
if (str == null) {
|
||||
str = this.doc.getLine(row).substring(0, column)
|
||||
}
|
||||
var str = this.session.getLine(row).substring(0, column);
|
||||
var leftOfCursor = lang.stringReverse(str);
|
||||
var index = this.$shortWordEndIndex(leftOfCursor);
|
||||
|
||||
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);
|
||||
return this.moveCursorTo(row, column - index);
|
||||
};
|
||||
|
||||
this.moveCursorWordRight = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue