fix unit tests
This commit is contained in:
parent
9027485ddb
commit
c0c02e8e3f
6 changed files with 16 additions and 20 deletions
|
|
@ -98,7 +98,7 @@ var EditSession = function(text, mode) {
|
||||||
this.setValue = function(text) {
|
this.setValue = function(text) {
|
||||||
this.doc.setValue(text);
|
this.doc.setValue(text);
|
||||||
this.$deltas = [];
|
this.$deltas = [];
|
||||||
this.$undoManager.reset();
|
this.getUndoManager().reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getValue =
|
this.getValue =
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ var Editor =function(renderer, session) {
|
||||||
if (this.session) {
|
if (this.session) {
|
||||||
var oldSession = this.session;
|
var oldSession = this.session;
|
||||||
this.session.removeEventListener("change", this.$onDocumentChange);
|
this.session.removeEventListener("change", this.$onDocumentChange);
|
||||||
this.session.removeEventListener("changeMode", this.$onModeChange);
|
this.session.removeEventListener("changeMode", this.$onChangeMode);
|
||||||
this.session.removeEventListener("changeTabSize", this.$onChangeTabSize);
|
this.session.removeEventListener("changeTabSize", this.$onChangeTabSize);
|
||||||
this.session.removeEventListener("changeWrapLimit", this.$onChangeWrapLimit);
|
this.session.removeEventListener("changeWrapLimit", this.$onChangeWrapLimit);
|
||||||
this.session.removeEventListener("changeWrapMode", this.$onChangeWrapMode);
|
this.session.removeEventListener("changeWrapMode", this.$onChangeWrapMode);
|
||||||
|
|
@ -144,8 +144,8 @@ var Editor =function(renderer, session) {
|
||||||
session.addEventListener("change", this.$onDocumentChange);
|
session.addEventListener("change", this.$onDocumentChange);
|
||||||
this.renderer.setSession(session);
|
this.renderer.setSession(session);
|
||||||
|
|
||||||
this.$onModeChange = this.onModeChange.bind(this);
|
this.$onChangeMode = this.onChangeMode.bind(this);
|
||||||
session.addEventListener("changeMode", this.$onModeChange);
|
session.addEventListener("changeMode", this.$onChangeMode);
|
||||||
|
|
||||||
this.$onChangeTabSize = this.renderer.updateText.bind(this.renderer);
|
this.$onChangeTabSize = this.renderer.updateText.bind(this.renderer);
|
||||||
session.addEventListener("changeTabSize", this.$onChangeTabSize);
|
session.addEventListener("changeTabSize", this.$onChangeTabSize);
|
||||||
|
|
@ -177,7 +177,7 @@ var Editor =function(renderer, session) {
|
||||||
this.$onSelectionChange = this.onSelectionChange.bind(this);
|
this.$onSelectionChange = this.onSelectionChange.bind(this);
|
||||||
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
|
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
|
||||||
|
|
||||||
this.onModeChange();
|
this.onChangeMode();
|
||||||
this.bgTokenizer.setDocument(session.getDocument());
|
this.bgTokenizer.setDocument(session.getDocument());
|
||||||
this.bgTokenizer.start(0);
|
this.bgTokenizer.start(0);
|
||||||
|
|
||||||
|
|
@ -357,7 +357,7 @@ var Editor =function(renderer, session) {
|
||||||
this.renderer.setAnnotations(this.session.getAnnotations());
|
this.renderer.setAnnotations(this.session.getAnnotations());
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onModeChange = function() {
|
this.onChangeMode = function() {
|
||||||
var mode = this.session.getMode();
|
var mode = this.session.getMode();
|
||||||
if (this.mode == mode)
|
if (this.mode == mode)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ var Test = {
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: should use mode of new document" : function() {
|
"test: should use mode of new document" : function() {
|
||||||
this.editor.onDocumentModeChange = function() {
|
this.editor.onChangeMode = function() {
|
||||||
called = true;
|
called = true;
|
||||||
};
|
};
|
||||||
this.editor.setSession(this.session1);
|
this.editor.setSession(this.session1);
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,12 @@ var lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
|
||||||
"consectetur";
|
"consectetur";
|
||||||
|
|
||||||
var Test = {
|
var Test = {
|
||||||
setUp: function() {
|
setUp: function(next) {
|
||||||
this.session = new EditSession(lipsum);
|
this.session = new EditSession(lipsum);
|
||||||
this.editor = new Editor(new MockRenderer(), this.session);
|
this.editor = new Editor(new MockRenderer(), this.session);
|
||||||
this.selection = this.session.getSelection();
|
this.selection = this.session.getSelection();
|
||||||
this.search = this.editor.$search;
|
this.search = this.editor.$search;
|
||||||
|
next();
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: highlight selected words by default": function() {
|
"test: highlight selected words by default": function() {
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,6 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
MockRenderer = function(visibleRowCount) {
|
MockRenderer = function(visibleRowCount) {
|
||||||
this.container = document.createElement("div");
|
this.container = document.createElement("div");
|
||||||
this.cursor = {
|
|
||||||
row : 0,
|
|
||||||
column : 0
|
|
||||||
};
|
|
||||||
|
|
||||||
this.visibleRowCount = visibleRowCount || 20;
|
this.visibleRowCount = visibleRowCount || 20;
|
||||||
|
|
||||||
this.layerConfig = {
|
this.layerConfig = {
|
||||||
|
|
@ -89,9 +84,7 @@ MockRenderer.prototype.getSession = function(session) {
|
||||||
MockRenderer.prototype.setTokenizer = function() {
|
MockRenderer.prototype.setTokenizer = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
MockRenderer.prototype.updateCursor = function(position) {
|
MockRenderer.prototype.updateCursor = function() {
|
||||||
this.cursor.row = position.row;
|
|
||||||
this.cursor.column = position.column;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MockRenderer.prototype.scrollToLine = function(line, center) {
|
MockRenderer.prototype.scrollToLine = function(line, center) {
|
||||||
|
|
@ -108,11 +101,12 @@ MockRenderer.prototype.scrollToLine = function(line, center) {
|
||||||
};
|
};
|
||||||
|
|
||||||
MockRenderer.prototype.scrollCursorIntoView = function() {
|
MockRenderer.prototype.scrollCursorIntoView = function() {
|
||||||
if (this.cursor.row < this.layerConfig.firstVisibleRow) {
|
var cursor = this.session.getSelection().getCursor();
|
||||||
this.scrollToRow(this.cursor.row);
|
if (cursor.row < this.layerConfig.firstVisibleRow) {
|
||||||
|
this.scrollToRow(cursor.row);
|
||||||
}
|
}
|
||||||
else if (this.cursor.row > this.layerConfig.lastVisibleRow) {
|
else if (cursor.row > this.layerConfig.lastVisibleRow) {
|
||||||
this.scrollToRow(this.cursor.row);
|
this.scrollToRow(cursor.row);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ var Test = {
|
||||||
document.body.appendChild(el);
|
document.body.appendChild(el);
|
||||||
|
|
||||||
var renderer = new VirtualRenderer(el);
|
var renderer = new VirtualRenderer(el);
|
||||||
|
renderer.setPadding(0);
|
||||||
renderer.setSession(new EditSession("1234"));
|
renderer.setSession(new EditSession("1234"));
|
||||||
|
|
||||||
renderer.characterWidth = 10;
|
renderer.characterWidth = 10;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue