From 64a55719b20f1d0d3098e343160a5104f3608a05 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 23 May 2011 13:20:17 +0500 Subject: [PATCH] eliminate scrollbar jitter while typing at the bottom of screen --- lib/ace/virtual_renderer.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index a9687660..31a9eeff 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -95,7 +95,7 @@ var VirtualRenderer = function(container, theme) { this.scrollBar = new ScrollBar(container); this.scrollBar.addEventListener("scroll", this.onScroll.bind(this)); - this.scrollTop = 0; + this.scrollTop = this.desiredScrollTop = 0; this.cursorPos = { row : 0, @@ -384,7 +384,7 @@ var VirtualRenderer = function(container, theme) { }; this.$updateScrollBar = function() { - this.scrollBar.setInnerHeight(this.session.getScreenLength() * this.lineHeight); + this.scrollBar.setInnerHeight(this.layerConfig.maxHeight); this.scrollBar.setScrollTop(this.scrollTop); }; @@ -469,6 +469,10 @@ var VirtualRenderer = function(container, theme) { if (horizScrollChanged) this.scroller.style.overflowX = horizScroll ? "scroll" : "hidden"; + var maxHeight = this.session.getScreenLength() * this.lineHeight; + this.scrollTop = this.desiredScrollTop = + Math.max(0, Math.min(this.desiredScrollTop, maxHeight - this.$size.scrollerHeight)); + var lineCount = Math.ceil(minHeight / this.lineHeight) - 1; var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight)); var lastRow = firstRow + lineCount; @@ -494,7 +498,7 @@ var VirtualRenderer = function(container, theme) { offset = this.scrollTop - firstRowScreen * this.lineHeight; - var layerConfig = this.layerConfig = { + this.layerConfig = { width : longestLine, padding : this.$padding, firstRow : firstRow, @@ -503,12 +507,13 @@ var VirtualRenderer = function(container, theme) { lineHeight : this.lineHeight, characterWidth : this.characterWidth, minHeight : minHeight, + maxHeight : maxHeight, offset : offset, height : this.$size.scrollerHeight }; // For debugging. - // console.log(JSON.stringify(layerConfig)); + // console.log(JSON.stringify(this.layerConfig)); this.$gutterLayer.element.style.marginTop = (-offset) + "px"; this.content.style.marginTop = (-offset) + "px"; @@ -662,12 +667,11 @@ var VirtualRenderer = function(container, theme) { }; this.scrollToY = function(scrollTop) { - var maxHeight = this.session.getScreenLength() * this.lineHeight - this.$size.scrollerHeight; - var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop)); - + // after calling scrollBar.setScrollTop + // scrollbar sends us event with same scrollTop. ignore it if (this.scrollTop !== scrollTop) { - this.scrollTop = scrollTop; this.$loop.schedule(this.CHANGE_SCROLL); + this.desiredScrollTop = scrollTop; } };