diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 96b14c48..8b0ab4c9 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -812,6 +812,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();