minor fixes

This commit is contained in:
Fabian Jakobs 2011-08-04 17:55:20 +02:00
commit c372ec5c9a
4 changed files with 41 additions and 17 deletions

View file

@ -73,15 +73,13 @@ var lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
module.exports = { module.exports = {
setUp: function(next) { setUp: function() {
this.buffer = new Buffer(lipsum); this.buffer = new Buffer(lipsum);
this.selection = this.buffer.getSelection(); this.selection = this.buffer.getSelection();
this.search = new Search(); this.search = new Search();
this.win = new Window({}, this.search); this.win = new Window({}, this.search);
this.winController = new WindowController(this.win, new WindowViewMock()); this.winController = new WindowController(this.win, new WindowViewMock());
this.win.setBuffer(this.buffer); this.win.setBuffer(this.buffer);
next();
}, },
"test: highlight selected words by default": function() { "test: highlight selected words by default": function() {

View file

@ -50,17 +50,47 @@ module.exports = {
setUp: function() { setUp: function() {
this.win = new Window(); this.win = new Window();
this.win.setBuffer(this.createBuffer(200, 5));
this.win.setSizes({
heigth: 410,
width: 640,
scrollerHeight: 400,
scrollerWidth: 600
});
this.win.setComputedCharacterSize({width: 10, height: 20});
this.win.updateLayerConfig();
},
createBuffer: function(rows, cols) {
var line = new Array(cols + 1).join("a");
var text = new Array(rows).join(line + "\n") + line;
return new Buffer(text);
}, },
"test setting a buffer chould emit a change event": function() { "test setting a buffer chould emit a change event": function() {
assert.eventFired(this.win, "changeBuffer", function() { assert.eventFired(this.win, "changeBuffer", function() {
this.win.setBuffer(new Buffer("")); this.win.setBuffer(new Buffer(""));
}, this); }, this);
},
"test compute layer config when scrolled to the top": function() {
var config = this.win.layerConfig;
assert.equal(config.width, 600);
assert.equal(config.height, 400);
assert.equal(config.minHeight, 440); // ??
assert.equal(config.maxHeight, 200*20);
assert.equal(config.offset, 0);
assert.equal(config.firstRow, 0);
assert.equal(config.lastRow, 20);
},
"test get last visible row": function() {
assert.equal(this.win.getLastVisibleRow(), 19);
} }
}; };
}); });
if (typeof module !== "undefined" && module === require.main) { if (typeof module !== "undefined" && module === require.main) {
require("asyncjs/test").testcase(module.exports).exec() require("asyncjs").test.testcase(module.exports).exec()
} }

View file

@ -127,7 +127,7 @@ var WindowView = function(windowModel, container) {
oop.implement(this, EventEmitter); oop.implement(this, EventEmitter);
// TODO refctor // TODO refactor
// remove // remove
this.setSession = function(session) { this.setSession = function(session) {
this.$textLayer.setSession(session); this.$textLayer.setSession(session);
@ -171,10 +171,6 @@ var WindowView = function(windowModel, container) {
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
}; };
this.updateFontSize = function() {
this.$textLayer.checkForSizeChanges();
};
this.measureSizes = function() { this.measureSizes = function() {
var width = dom.getInnerWidth(this.container); var width = dom.getInnerWidth(this.container);
var gutterWidth = this.model.showGutter ? this.$gutter.offsetWidth : 0; var gutterWidth = this.model.showGutter ? this.$gutter.offsetWidth : 0;

View file

@ -95,10 +95,10 @@ var WindowController = exports.WindowController = function(model, view) {
oldBuffer.removeListener("changeBackMarker", this._onChangeBackMarker); oldBuffer.removeListener("changeBackMarker", this._onChangeBackMarker);
oldBuffer.removeListener("changeBreakpoint", this._onChangeBreakpoint); oldBuffer.removeListener("changeBreakpoint", this._onChangeBreakpoint);
oldBuffer.removeListener("changeAnnotation", this._onChangeAnnotation); oldBuffer.removeListener("changeAnnotation", this._onChangeAnnotation);
oldBuffer.removeListener("changeOverwrite", this._onCursorChange); oldBuffer.removeListener("changeOverwrite", this._onChangeCursor);
var selection = oldBuffer.getSelection(); var selection = oldBuffer.getSelection();
selection.removeEventListener("changeCursor", this._onCursorChange); selection.removeEventListener("changeCursor", this._onChangeCursor);
selection.removeEventListener("changeSelection", this._onSelectionChange); selection.removeEventListener("changeSelection", this._onSelectionChange);
} }
@ -138,11 +138,11 @@ var WindowController = exports.WindowController = function(model, view) {
this._onChangeAnnotation = this.onChangeAnnotation.bind(this); this._onChangeAnnotation = this.onChangeAnnotation.bind(this);
buffer.on("changeAnnotation", this._onChangeAnnotation); buffer.on("changeAnnotation", this._onChangeAnnotation);
this._onCursorChange = this.onCursorChange.bind(this); this._onChangeCursor = this.onChangeCursor.bind(this);
buffer.on("changeOverwrite", this._onCursorChange); buffer.on("changeOverwrite", this._onChangeCursor);
this.selection = buffer.getSelection(); this.selection = buffer.getSelection();
this.selection.on("changeCursor", this._onCursorChange); this.selection.on("changeCursor", this._onChangeCursor);
this._onSelectionChange = this.onSelectionChange.bind(this); this._onSelectionChange = this.onSelectionChange.bind(this);
this.selection.on("changeSelection", this._onSelectionChange); this.selection.on("changeSelection", this._onSelectionChange);
@ -154,7 +154,7 @@ var WindowController = exports.WindowController = function(model, view) {
if (buffer.getUseWrapMode()) if (buffer.getUseWrapMode())
this.view.adjustWrapLimit(); this.view.adjustWrapLimit();
this.onCursorChange(); this.onChangeCursor();
this.onSelectionChange(); this.onSelectionChange();
this.view.updateFull(); this.view.updateFull();
@ -199,7 +199,7 @@ var WindowController = exports.WindowController = function(model, view) {
this.view.setAnnotations(this.model.buffer.getAnnotations()); this.view.setAnnotations(this.model.buffer.getAnnotations());
}; };
this.onCursorChange = function(e) { this.onChangeCursor = function(e) {
this.view.updateCursor(); this.view.updateCursor();
this.model.scrollCursorIntoView(); this.model.scrollCursorIntoView();