computations involving pixels don't belong in the buffer

This commit is contained in:
Fabian Jakobs 2011-07-28 10:53:43 +02:00
commit e96918892a
3 changed files with 21 additions and 25 deletions

View file

@ -1377,13 +1377,6 @@ var Buffer = function(text, mode) {
}
}
/**
* Returns the height in pixels required to render this row on the screen
**/
this.getRowHeight = function(config, row) {
return this.getRowLength(row) * config.lineHeight;
}
this.getScreenLastRowColumn = function(screenRow) {
//return this.screenToDocumentColumn(screenRow, Number.MAX_VALUE / 10)
return this.documentToScreenColumn(screenRow, this.doc.getLine(screenRow).length);

View file

@ -133,7 +133,14 @@ var Window = exports.Window = function(theme) {
top : cursorTop
};
};
/**
* Returns the height in pixels required to render this row on the screen
**/
this.getRowHeight = function(row) {
return this.buffer.getRowLength(row) * this.characterSize.height;
};
// SCROLLING
this.scrollToY = function(scrollTop) {
@ -182,15 +189,13 @@ var Window = exports.Window = function(theme) {
};
this.scrollToLine = function(line, center) {
var lineHeight = { lineHeight: this.characterSize.height };
var offset = 0;
for (var l = 1; l < line; l++) {
offset += this.buffer.getRowHeight(lineHeight, l-1);
}
for (var l = 1; l < line; l++)
offset += this.getRowHeight(l-1);
if (center) {
if (center)
offset -= this.size.scrollerHeight / 2;
}
this.scrollToY(offset);
};

View file

@ -91,10 +91,12 @@ var WindowView = function(windowModel, container) {
this.$cursorLayer = new CursorLayer(windowModel, this.content);
this.$horizScroll = true;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
var _self = this;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", function(e) {
_self.model.scrollToY(e.data);
});
event.addListener(this.scroller, "scroll", function() {
windowModel.scrollToX(_self.scroller.scrollLeft);
});
@ -308,10 +310,6 @@ var WindowView = function(windowModel, container) {
this.$loop.schedule(this.CHANGE_FULL);
};
this.onScroll = function(e) {
this.model.scrollToY(e.data);
};
this.$updateScrollBar = function() {
this.scrollBar.setInnerHeight(this.model.layerConfig.maxHeight);
this.scrollBar.setScrollTop(this.model.scrollTop);
@ -412,7 +410,6 @@ var WindowView = function(windowModel, container) {
// Map lines on the screen to lines in the document.
var firstRowScreen, firstRowHeight;
var lineHeight = { lineHeight: this.lineHeight };
firstRow = session.screenToDocumentRow(firstRow, 0);
// Check if firstRow is inside of a foldLine. If true, then use the first
@ -423,11 +420,12 @@ var WindowView = function(windowModel, container) {
}
firstRowScreen = session.documentToScreenRow(firstRow, 0);
firstRowHeight = session.getRowHeight(lineHeight, firstRow);
firstRowHeight = this.model.getRowHeight(firstRow);
lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
minHeight = this.model.size.scrollerHeight + session.getRowHeight(lineHeight, lastRow)+
firstRowHeight;
minHeight = this.model.size.scrollerHeight
+ this.model.getRowHeight(lastRow)
+ firstRowHeight;
offset = this.model.scrollTop - firstRowScreen * this.lineHeight;