fix unit tests

This commit is contained in:
Fabian Jakobs 2011-02-21 09:21:07 +01:00
commit c0c02e8e3f
6 changed files with 16 additions and 20 deletions

View file

@ -98,7 +98,7 @@ var EditSession = function(text, mode) {
this.setValue = function(text) {
this.doc.setValue(text);
this.$deltas = [];
this.$undoManager.reset();
this.getUndoManager().reset();
};
this.getValue =

View file

@ -121,7 +121,7 @@ var Editor =function(renderer, session) {
if (this.session) {
var oldSession = this.session;
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("changeWrapLimit", this.$onChangeWrapLimit);
this.session.removeEventListener("changeWrapMode", this.$onChangeWrapMode);
@ -144,8 +144,8 @@ var Editor =function(renderer, session) {
session.addEventListener("change", this.$onDocumentChange);
this.renderer.setSession(session);
this.$onModeChange = this.onModeChange.bind(this);
session.addEventListener("changeMode", this.$onModeChange);
this.$onChangeMode = this.onChangeMode.bind(this);
session.addEventListener("changeMode", this.$onChangeMode);
this.$onChangeTabSize = this.renderer.updateText.bind(this.renderer);
session.addEventListener("changeTabSize", this.$onChangeTabSize);
@ -177,7 +177,7 @@ var Editor =function(renderer, session) {
this.$onSelectionChange = this.onSelectionChange.bind(this);
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
this.onModeChange();
this.onChangeMode();
this.bgTokenizer.setDocument(session.getDocument());
this.bgTokenizer.start(0);
@ -357,7 +357,7 @@ var Editor =function(renderer, session) {
this.renderer.setAnnotations(this.session.getAnnotations());
};
this.onModeChange = function() {
this.onChangeMode = function() {
var mode = this.session.getMode();
if (this.mode == mode)
return;

View file

@ -138,7 +138,7 @@ var Test = {
},
"test: should use mode of new document" : function() {
this.editor.onDocumentModeChange = function() {
this.editor.onChangeMode = function() {
called = true;
};
this.editor.setSession(this.session1);

View file

@ -67,11 +67,12 @@ var lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
"consectetur";
var Test = {
setUp: function() {
setUp: function(next) {
this.session = new EditSession(lipsum);
this.editor = new Editor(new MockRenderer(), this.session);
this.selection = this.session.getSelection();
this.search = this.editor.$search;
next();
},
"test: highlight selected words by default": function() {

View file

@ -39,11 +39,6 @@ define(function(require, exports, module) {
MockRenderer = function(visibleRowCount) {
this.container = document.createElement("div");
this.cursor = {
row : 0,
column : 0
};
this.visibleRowCount = visibleRowCount || 20;
this.layerConfig = {
@ -89,9 +84,7 @@ MockRenderer.prototype.getSession = function(session) {
MockRenderer.prototype.setTokenizer = function() {
};
MockRenderer.prototype.updateCursor = function(position) {
this.cursor.row = position.row;
this.cursor.column = position.column;
MockRenderer.prototype.updateCursor = function() {
};
MockRenderer.prototype.scrollToLine = function(line, center) {
@ -108,11 +101,12 @@ MockRenderer.prototype.scrollToLine = function(line, center) {
};
MockRenderer.prototype.scrollCursorIntoView = function() {
if (this.cursor.row < this.layerConfig.firstVisibleRow) {
this.scrollToRow(this.cursor.row);
var cursor = this.session.getSelection().getCursor();
if (cursor.row < this.layerConfig.firstVisibleRow) {
this.scrollToRow(cursor.row);
}
else if (this.cursor.row > this.layerConfig.lastVisibleRow) {
this.scrollToRow(this.cursor.row);
else if (cursor.row > this.layerConfig.lastVisibleRow) {
this.scrollToRow(cursor.row);
}
};

View file

@ -53,6 +53,7 @@ var Test = {
document.body.appendChild(el);
var renderer = new VirtualRenderer(el);
renderer.setPadding(0);
renderer.setSession(new EditSession("1234"));
renderer.characterWidth = 10;