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
|
|
@ -37,7 +37,7 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockIndent(" ");
|
||||
|
||||
|
|
@ -46,9 +46,9 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
|
||||
assertPosition(2, 7, editor.getCursorPosition());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assertPosition(1, 7, selection.start);
|
||||
assertPosition(2, 7, selection.end);
|
||||
var range = editor.getSelectionRange();
|
||||
assertPosition(1, 7, range.start);
|
||||
assertPosition(2, 7, range.end);
|
||||
},
|
||||
|
||||
"test: outdent block" : function() {
|
||||
|
|
@ -56,8 +56,8 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 3);
|
||||
editor.selectDown();
|
||||
editor.selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent(" ");
|
||||
assertEquals([" a12345", "b12345", " c12345"].join("\n"),
|
||||
|
|
@ -65,18 +65,18 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
|
||||
assertPosition(2, 1, editor.getCursorPosition());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assertPosition(0, 1, selection.start);
|
||||
assertPosition(2, 1, selection.end);
|
||||
var range = editor.getSelectionRange();
|
||||
assertPosition(0, 1, range.start);
|
||||
assertPosition(2, 1, range.end);
|
||||
|
||||
|
||||
editor.blockOutdent(" ");
|
||||
assertEquals([" a12345", "b12345", " c12345"].join("\n"),
|
||||
doc.toString());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assertPosition(0, 1, selection.start);
|
||||
assertPosition(2, 1, selection.end);
|
||||
var range = editor.getSelectionRange();
|
||||
assertPosition(0, 1, range.start);
|
||||
assertPosition(2, 1, range.end);
|
||||
},
|
||||
|
||||
"test: outent without a selection should update cursor" : function() {
|
||||
|
|
@ -95,7 +95,7 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
var editor = new ace.Editor(new MockRenderer(), doc, new ace.mode.JavaScript());
|
||||
|
||||
editor.moveCursorTo(0, 2);
|
||||
editor.selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
|
|
@ -111,9 +111,9 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
var editor = new ace.Editor(new MockRenderer(), doc, new ace.mode.JavaScript());
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.selectDown();
|
||||
editor.selectRight();
|
||||
editor.selectRight();
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectRight();
|
||||
editor.getSelection().selectRight();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
|
|
@ -129,26 +129,26 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assertEquals(["33", "11", "22", "44"].join("\n"), doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 0, editor.getSelectionAnchor());
|
||||
assertPosition(1, 0, editor.getSelectionLead());
|
||||
assertPosition(3, 0, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(1, 0, editor.getSelection().getSelectionLead());
|
||||
|
||||
editor.moveLinesDown();
|
||||
assertEquals(["33", "44", "11", "22"].join("\n"), doc.toString());
|
||||
assertPosition(2, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 2, editor.getSelectionAnchor());
|
||||
assertPosition(2, 0, editor.getSelectionLead());
|
||||
assertPosition(3, 2, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(2, 0, editor.getSelection().getSelectionLead());
|
||||
|
||||
// moving again should have no effect
|
||||
editor.moveLinesDown();
|
||||
assertEquals(["33", "44", "11", "22"].join("\n"), doc.toString());
|
||||
assertPosition(2, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 2, editor.getSelectionAnchor());
|
||||
assertPosition(2, 0, editor.getSelectionLead());
|
||||
assertPosition(3, 2, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(2, 0, editor.getSelection().getSelectionLead());
|
||||
},
|
||||
|
||||
"test: move lines up should select moved lines" : function() {
|
||||
|
|
@ -156,19 +156,19 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(2, 1);
|
||||
editor.selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assertEquals(["11", "33", "44", "22"].join("\n"), doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 0, editor.getSelectionAnchor());
|
||||
assertPosition(1, 0, editor.getSelectionLead());
|
||||
assertPosition(3, 0, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(1, 0, editor.getSelection().getSelectionLead());
|
||||
|
||||
editor.moveLinesUp();
|
||||
assertEquals(["33", "44", "11", "22"].join("\n"), doc.toString());
|
||||
assertPosition(0, 0, editor.getCursorPosition());
|
||||
assertPosition(2, 0, editor.getSelectionAnchor());
|
||||
assertPosition(0, 0, editor.getSelectionLead());
|
||||
assertPosition(2, 0, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(0, 0, editor.getSelection().getSelectionLead());
|
||||
},
|
||||
|
||||
"test: move line without active selection should move cursor to start of the moved line" : function()
|
||||
|
|
@ -188,5 +188,30 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
editor.moveLinesUp();
|
||||
assertEquals(["11", "22", "33", "44"].join("\n"), doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: input a tab with soft tab should convert it to spaces" : function() {
|
||||
var doc = new ace.TextDocument("");
|
||||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.setTabSize(2);
|
||||
editor.setUseSoftTabs(true);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assertEquals(" ", doc.toString());
|
||||
|
||||
editor.setTabSize(5);
|
||||
editor.onTextInput("\t");
|
||||
assertEquals(" ", doc.toString());
|
||||
},
|
||||
|
||||
"test: input tab without soft tabs should keep the tab character" : function() {
|
||||
var doc = new ace.TextDocument("");
|
||||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.setUseSoftTabs(false);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assertEquals("\t", doc.toString());
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue