Merge pull request #531 from ajaxorg/vim_methods
Added `getAWordRange` and `selectAWord` methods
This commit is contained in:
commit
7e84cef35b
3 changed files with 73 additions and 43 deletions
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -248,6 +248,18 @@ module.exports = {
|
||||||
assert.position(range.end, 0, 12);
|
assert.position(range.end, 0, 12);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"test: select word with cursor in word including right whitespace should select the word" : function() {
|
||||||
|
var session = new EditSession("Juhu Kinners 123");
|
||||||
|
var selection = session.getSelection();
|
||||||
|
|
||||||
|
selection.moveCursorTo(0, 8);
|
||||||
|
selection.selectAWord();
|
||||||
|
|
||||||
|
var range = selection.getRange();
|
||||||
|
assert.position(range.start, 0, 5);
|
||||||
|
assert.position(range.end, 0, 18);
|
||||||
|
},
|
||||||
|
|
||||||
"test: select word with cursor betwen white space and word should select the word" : function() {
|
"test: select word with cursor betwen white space and word should select the word" : function() {
|
||||||
var session = new EditSession("Juhu Kinners");
|
var session = new EditSession("Juhu Kinners");
|
||||||
var selection = session.getSelection();
|
var selection = session.getSelection();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue