From fd126e06c363f64f5efb7095cada76a555fd7d5e Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 1 Dec 2012 17:11:37 +0400 Subject: [PATCH 1/5] fix bug in rowCache --- lib/ace/edit_session.js | 19 ++++++++++++------- lib/ace/edit_session_test.js | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index bfa85335..2402a51c 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -244,7 +244,7 @@ var EditSession = function(text, mode) { return mid; } - return low && low -1; + return low -1; }; this.resetCaches = function() { @@ -2164,12 +2164,13 @@ var EditSession = function(text, mode) { var rowCache = this.$screenRowCache; var i = this.$getRowCacheIndex(rowCache, screenRow); - if (0 < i && i < rowCache.length) { + var l = rowCache.length; + if (l && i >= 0) { var row = rowCache[i]; var docRow = this.$docRowCache[i]; - var doCache = screenRow > row || (screenRow == row && i == rowCache.length - 1); + var doCache = screenRow > rowCache[l - 1]; } else { - var doCache = i != 0 || !rowCache.length; + var doCache = !l; } var maxRow = this.getLength() - 1; @@ -2189,6 +2190,8 @@ var EditSession = function(text, mode) { foldStart = foldLine ? foldLine.start.row : Infinity; } } + + // if (rowCache[rowCache.length-1] >= row)console.error("---------") if (doCache) { this.$docRowCache.push(docRow); this.$screenRowCache.push(row); @@ -2269,12 +2272,13 @@ var EditSession = function(text, mode) { var rowCache = this.$docRowCache; var i = this.$getRowCacheIndex(rowCache, docRow); - if (0 < i && i < rowCache.length) { + var l = rowCache.length; + if (l && i >= 0) { var row = rowCache[i]; var screenRow = this.$screenRowCache[i]; - var doCache = docRow > row || (docRow == row && i == rowCache.length - 1); + var doCache = docRow > rowCache[l - 1]; } else { - var doCache = i != 0 || !rowCache.length; + var doCache = !l; } var foldLine = this.getNextFoldLine(row); @@ -2295,6 +2299,7 @@ var EditSession = function(text, mode) { screenRow += this.getRowLength(row); row = rowEnd; + // if (rowCache[rowCache.length-1] >= row)console.error("---------") if (doCache) { this.$docRowCache.push(row); this.$screenRowCache.push(screenRow); diff --git a/lib/ace/edit_session_test.js b/lib/ace/edit_session_test.js index e89ad57f..07d6b375 100644 --- a/lib/ace/edit_session_test.js +++ b/lib/ace/edit_session_test.js @@ -62,6 +62,7 @@ function createFoldTestSession() { } function assertArray(a, b) { + assert.equal(a+"", b+""); assert.ok(a.length == b.length); for (var i = 0; i < a.length; i++) { assert.equal(a[i], b[i]); @@ -980,7 +981,8 @@ module.exports = { assertArray(session.$docRowCache, [1,3,4]); assertArray(session.$screenRowCache, [1,2,3]); - session.screenToDocumentPosition(0,0); + var pos = session.screenToDocumentPosition(0,0); + assert.equal(pos.row, 0); assertArray(session.$docRowCache, [1,3,4]); assertArray(session.$screenRowCache, [1,2,3]); @@ -991,6 +993,20 @@ module.exports = { session.$resetRowCache(); assertArray(session.$docRowCache, []); assertArray(session.$screenRowCache, []); + + session.screenToDocumentPosition(1,3); + assertArray(session.$docRowCache, [1]); + assertArray(session.$screenRowCache, [1]); + + session.screenToDocumentPosition(5,3); + assertArray(session.$docRowCache, [1,3,4]); + assertArray(session.$screenRowCache, [1,2,3]); + + session = new EditSession(new Array(30).join("\n")); + session.documentToScreenPosition(2,0); + session.documentToScreenPosition(2,0); + assertArray(session.$docRowCache, [1,2]); + assertArray(session.$screenRowCache, [1,2]); } }; From b6890497c80407accd15ed358cacac895905569a Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 18 Nov 2012 01:47:07 +0400 Subject: [PATCH 2/5] do not redraw after changes to scrolled out lines --- lib/ace/virtual_renderer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index d5662ca6..6b0d467d 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -239,7 +239,10 @@ var VirtualRenderer = function(container, theme) { if (this.$changedLines.lastRow < lastRow) this.$changedLines.lastRow = lastRow; } - + + if (this.$changedLines.firstRow > this.layerConfig.lastRow || + this.$changedLines.lastRow < this.layerConfig.firstRow) + return; this.$loop.schedule(this.CHANGE_LINES); }; From b0bbb369235690e64d8e1882788f5f4823a0c005 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 8 Dec 2012 22:19:37 +0400 Subject: [PATCH 3/5] fix editor automatically scrolling up at small zoom --- lib/ace/scrollbar.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ace/scrollbar.js b/lib/ace/scrollbar.js index b667881c..36619bd5 100644 --- a/lib/ace/scrollbar.js +++ b/lib/ace/scrollbar.js @@ -85,7 +85,11 @@ var ScrollBar = function(parent) { * **/ this.onScroll = function() { - this._emit("scroll", {data: this.element.scrollTop}); + if (!this.skipEvent) { + this.scrollTop = this.element.scrollTop; + this._emit("scroll", {data: this.scrollTop}); + } + this.skipEvent = false; }; /** @@ -120,7 +124,7 @@ var ScrollBar = function(parent) { }; - // TODO: on chrome 17+ for small zoom levels after calling this function + // on chrome 17+ for small zoom levels after calling this function // this.element.scrollTop != scrollTop which makes page to scroll up. /** * Sets the scroll top of the scroll bar. @@ -130,7 +134,10 @@ var ScrollBar = function(parent) { * **/ this.setScrollTop = function(scrollTop) { - this.element.scrollTop = scrollTop; + if (this.scrollTop != scrollTop) { + this.skipEvent = true; + this.scrollTop = this.element.scrollTop = scrollTop; + } }; }).call(ScrollBar.prototype); From c68bed51e0d51d1ab6351dd1908fb808df6cfcba Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Dec 2012 18:36:01 +0400 Subject: [PATCH 4/5] make gutter resizing faster --- lib/ace/virtual_renderer.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 6b0d467d..86cd84db 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -96,7 +96,7 @@ var VirtualRenderer = function(container, theme) { this.setHighlightGutterLine(true); this.$gutterLayer = new GutterLayer(this.$gutter); - this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true)); + this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this)); this.$markerBack = new MarkerLayer(this.content); @@ -339,6 +339,16 @@ var VirtualRenderer = function(container, theme) { delete this.resizing; }; + this.onGutterResize = function() { + var width = this.$size.width; + var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0; + this.scroller.style.left = gutterWidth + "px"; + this.$size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth()); + + if (this.session.getUseWrapMode() && this.adjustWrapLimit()) + this.$loop.schedule(this.CHANGE_FULL); + }; + /** * * Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen. From 71b54a574125e1819f01ad2bfd2fb9581ae5476c Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 13 Dec 2012 19:00:39 +0400 Subject: [PATCH 5/5] remove unused log --- lib/ace/edit_session.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 2402a51c..8839eac6 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -2191,7 +2191,6 @@ var EditSession = function(text, mode) { } } - // if (rowCache[rowCache.length-1] >= row)console.error("---------") if (doCache) { this.$docRowCache.push(docRow); this.$screenRowCache.push(row); @@ -2299,7 +2298,6 @@ var EditSession = function(text, mode) { screenRow += this.getRowLength(row); row = rowEnd; - // if (rowCache[rowCache.length-1] >= row)console.error("---------") if (doCache) { this.$docRowCache.push(row); this.$screenRowCache.push(screenRow);