From 146d832e19591b0e85fee5cb4286a458d8781393 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 6 Aug 2014 13:10:41 +0100 Subject: [PATCH] Keep apparent scroll position fixed when changes are made offscreen --- lib/ace/virtual_renderer.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index dfb435be..60b7b779 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -809,6 +809,15 @@ var VirtualRenderer = function(container, theme) { changes & this.CHANGE_H_SCROLL ) { changes |= this.$computeLayerConfig(); + // If a change is made offscreen and wrapMode is on, then the onscreen + // lines may have been pushed down. If so, the first screen row will not + // have changed, but the first actual row will. In that case, adjust + // scrollTop so that the cursor and onscreen content stays in the same place. + if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) { + this.scrollTop = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight; + changes = changes | this.CHANGE_SCROLL; + changes |= this.$computeLayerConfig(); + } config = this.layerConfig; // update scrollbar first to not lose scroll position when gutter calls resize this.$updateScrollBarV();