changing the document is now possible
This commit is contained in:
parent
328dfacf47
commit
aecaea3ef1
6 changed files with 276 additions and 63 deletions
107
test/ChangeDocumentTest.js
Normal file
107
test/ChangeDocumentTest.js
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
var ChangeDocumentTest = new TestCase("ChangeDocumentTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.doc1 = new ace.TextDocument(["abc", "def"].join("\n"));
|
||||
this.doc2 = new ace.TextDocument(["ghi", "jkl"].join("\n"));
|
||||
this.editor = new ace.Editor(new MockRenderer());
|
||||
},
|
||||
|
||||
"test: change document" : function() {
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertEquals(this.doc1, this.editor.getDocument());
|
||||
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertEquals(this.doc2, this.editor.getDocument());
|
||||
},
|
||||
|
||||
"test: only changes to the new document should have effect" : function() {
|
||||
var called = false;
|
||||
this.editor.onDocumentChange = function() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
|
||||
this.doc1.duplicateLines(0, 0);
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.duplicateLines(0, 0);
|
||||
assertTrue(called);
|
||||
},
|
||||
|
||||
"test: should use cursor of new document" : function() {
|
||||
this.doc1.getSelection().moveCursorTo(0, 1);
|
||||
this.doc2.getSelection().moveCursorTo(1, 0);
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertPosition(0, 1, this.editor.getCursorPosition());
|
||||
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(1, 0, this.editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: only changing the cursor of the new doc should not have an effect" : function() {
|
||||
this.editor.onCursorChange = function() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(0, 0, this.editor.getCursorPosition());
|
||||
|
||||
var called = false;
|
||||
this.doc1.getSelection().moveCursorTo(0, 1);
|
||||
assertPosition(0, 0, this.editor.getCursorPosition());
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.getSelection().moveCursorTo(1, 1);
|
||||
assertPosition(1, 1, this.editor.getCursorPosition());
|
||||
assertTrue(called);
|
||||
},
|
||||
|
||||
"test: should use selection of new document" : function() {
|
||||
this.doc1.getSelection().selectTo(0, 1);
|
||||
this.doc2.getSelection().selectTo(1, 0);
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertPosition(0, 1, this.editor.getSelection().getSelectionLead());
|
||||
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(1, 0, this.editor.getSelection().getSelectionLead());
|
||||
},
|
||||
|
||||
"test: only changing the selection of the new doc should not have an effect" : function() {
|
||||
this.editor.onSelectionChange = function() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(0, 0, this.editor.getSelection().getSelectionLead());
|
||||
|
||||
var called = false;
|
||||
this.doc1.getSelection().selectTo(0, 1);
|
||||
assertPosition(0, 0, this.editor.getSelection().getSelectionLead());
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.getSelection().selectTo(1, 1);
|
||||
assertPosition(1, 1, this.editor.getSelection().getSelectionLead());
|
||||
assertTrue(called);
|
||||
},
|
||||
|
||||
"test: should use mode of new document" : function() {
|
||||
this.editor.onDocumentModeChange = function() {
|
||||
called = true;
|
||||
};
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
|
||||
var called = false;
|
||||
this.doc1.setMode(new ace.mode.Text());
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.setMode(new ace.mode.JavaScript());
|
||||
assertTrue(called);
|
||||
}
|
||||
});
|
||||
|
|
@ -118,8 +118,8 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
},
|
||||
|
||||
"test: comment lines should perserve selection" : function() {
|
||||
var doc = new ace.TextDocument([" abc", "cde"].join("\n"));
|
||||
var editor = new ace.Editor(new MockRenderer(), doc, new ace.mode.JavaScript());
|
||||
var doc = new ace.TextDocument([" abc", "cde"].join("\n"), new ace.mode.JavaScript());
|
||||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 2);
|
||||
editor.getSelection().selectDown();
|
||||
|
|
@ -134,8 +134,8 @@ var TextEditTest = TestCase("TextEditTest",
|
|||
},
|
||||
|
||||
"test: uncomment lines should perserve selection" : function() {
|
||||
var doc = new ace.TextDocument(["// abc", "//cde"].join("\n"));
|
||||
var editor = new ace.Editor(new MockRenderer(), doc, new ace.mode.JavaScript());
|
||||
var doc = new ace.TextDocument(["// abc", "//cde"].join("\n"), new ace.mode.JavaScript());
|
||||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue