Added getAWordRange and selectAWord methods

These new methods are necessary to select a word along with its right
whitespace, which is a reasonably common scenario.
This commit is contained in:
Sergi Mansilla 2011-11-24 18:18:01 +01:00
commit bb7fd9bb66
2 changed files with 25 additions and 7 deletions

View file

@ -441,6 +441,17 @@ var EditSession = function(text, mode) {
return new Range(row, start, row, end); return new Range(row, start, row, end);
}; };
// Gets the range of a word including its right whitespace
this.getAWordRange = function(row, column) {
var wordRange = this.getWordRange(row, column);
var line = this.getLine(wordRange.end.row);
while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
wordRange.end.column += 1;
}
return wordRange;
};
this.setNewLineMode = function(newLineMode) { this.setNewLineMode = function(newLineMode) {
this.doc.setNewLineMode(newLineMode); this.doc.setNewLineMode(newLineMode);
}; };

View file

@ -253,6 +253,13 @@ var Selection = function(session) {
this.setSelectionRange(range); this.setSelectionRange(range);
}; };
// Selects a word including its right whitespace
this.selectAWord = function() {
var cursor = this.getCursor();
var range = this.session.getAWordRange(cursor.row, cursor.column);
this.setSelectionRange(range);
};
this.selectLine = function() { this.selectLine = function() {
var rowStart = this.selectionLead.row; var rowStart = this.selectionLead.row;
var rowEnd; var rowEnd;