refactor selection support into a separate class
Merge branch 'master' into HEAD Conflicts: src/Editor.js src/KeyBinding.js src/Selection.js
This commit is contained in:
parent
b7e69d5da5
commit
7529f90080
12 changed files with 887 additions and 680 deletions
177
test/SelectionTest.js
Normal file
177
test/SelectionTest.js
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
var SelectionTest = TestCase("SelectionTest",
|
||||
{
|
||||
createTextDocument : function(rows, cols) {
|
||||
var line = new Array(cols + 1).join("a");
|
||||
var text = new Array(rows).join(line + "\n") + line;
|
||||
return new ace.TextDocument(text);
|
||||
},
|
||||
|
||||
"test: move cursor to end of file should place the cursor on last row and column" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorFileEnd();
|
||||
assertPosition(199, 10, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: moveCursor to start of file should place the cursor on the first row and column" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorFileStart();
|
||||
assertPosition(0, 0, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: move selection lead to end of file" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(100, 5);
|
||||
selection.selectFileEnd();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assertPosition(100, 5, range.start);
|
||||
assertPosition(199, 10, range.end);
|
||||
},
|
||||
|
||||
"test: move selection lead to start of file" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(100, 5);
|
||||
selection.selectFileStart();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assertPosition(0, 0, range.start);
|
||||
assertPosition(100, 5, range.end);
|
||||
},
|
||||
|
||||
"test: move cursor word right" : function() {
|
||||
var doc = new ace.TextDocument( ["ab",
|
||||
" Juhu Kinners (abc, 12)", " cde"].join("\n"));
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorDown();
|
||||
assertPosition(1, 0, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 1, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 5, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 6, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 13, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 15, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 18, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 20, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 22, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 23, selection.getCursor());
|
||||
|
||||
// wrap line
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(2, 0, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: select word right if cursor in word" : function() {
|
||||
var doc = new ace.TextDocument("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 2);
|
||||
selection.moveCursorWordRight();
|
||||
|
||||
assertPosition(0, 4, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: moveCursor word left" : function() {
|
||||
var doc = new ace.TextDocument( ["ab",
|
||||
" Juhu Kinners (abc, 12)", " cde"].join("\n"));
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorDown();
|
||||
selection.moveCursorLineEnd();
|
||||
assertPosition(1, 23, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 22, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 20, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 18, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 15, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 13, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 6, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 5, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 1, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 0, selection.getCursor());
|
||||
|
||||
// wrap line
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(0, 2, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: select word left if cursor in word" : function() {
|
||||
var doc = new ace.TextDocument("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(0, 5, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: select word right and select" : function() {
|
||||
var doc = new ace.TextDocument("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 0);
|
||||
selection.selectWordRight();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assertPosition(0, 0, range.start);
|
||||
assertPosition(0, 4, range.end);
|
||||
},
|
||||
|
||||
"test: select word left and select" : function() {
|
||||
var doc = new ace.TextDocument("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 3);
|
||||
selection.selectWordLeft();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assertPosition(0, 0, range.start);
|
||||
assertPosition(0, 3, range.end);
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue