diff --git a/lib/ace/model/buffer.js b/lib/ace/model/buffer.js index e1f7e46d..faf3ae30 100644 --- a/lib/ace/model/buffer.js +++ b/lib/ace/model/buffer.js @@ -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); diff --git a/lib/ace/model/window.js b/lib/ace/model/window.js index c85a22d8..456e9ebe 100644 --- a/lib/ace/model/window.js +++ b/lib/ace/model/window.js @@ -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); }; diff --git a/lib/ace/view/window_view.js b/lib/ace/view/window_view.js index 887567fe..5963bc2a 100644 --- a/lib/ace/view/window_view.js +++ b/lib/ace/view/window_view.js @@ -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;