From fd182ea76f370b31482e508c97ab8b8a45adb73a Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 10 Jul 2014 12:56:11 +0100 Subject: [PATCH 1/3] Redraw lines and active line highlight when offscreen updates are made When setUseWrapMode is true, if some text is inserted into a line which is above the cursor and offscreen, then the renderer did not previously redraw the lines or active line highlight. However, if this insert causes the line to wrap onto another line then everything is shifted down by one visual line, leaving the onscreen lines in an out of date state. With this commit, the onscreen lines and active line highlight are now redrawn when this happens. --- lib/ace/editor.js | 1 + lib/ace/virtual_renderer.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 6a68e5de..e198ecaa 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -708,6 +708,7 @@ var Editor = function(renderer, session) { // update cursor because tab characters can influence the cursor position this.$cursorChange(); + this.$updateHighlightActiveLine(); }; this.onTokenizerUpdate = function(e) { diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 33f3a906..dfb435be 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -276,8 +276,13 @@ var VirtualRenderer = function(container, theme) { this.$changedLines.lastRow = lastRow; } - if (this.$changedLines.firstRow > this.layerConfig.lastRow || - this.$changedLines.lastRow < this.layerConfig.firstRow) + // If the change happened offscreen above us then it's possible + // that a new line wrap will affect the position of the lines on our + // screen so they need redrawn. + if (this.$changedLines.lastRow < this.layerConfig.firstRow) + this.$changedLines.lastRow = this.layerConfig.lastRow + + if (this.$changedLines.firstRow > this.layerConfig.lastRow) return; this.$loop.schedule(this.CHANGE_LINES); }; From f4990b3a56d04b8245ad4b57199e56907b40c98d Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 1 Aug 2014 21:45:43 +0400 Subject: [PATCH 2/3] make sure text redraw isn't missed when bgTokenizer state changes --- lib/ace/background_tokenizer.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/ace/background_tokenizer.js b/lib/ace/background_tokenizer.js index b2ba3733..da8008bd 100644 --- a/lib/ace/background_tokenizer.js +++ b/lib/ace/background_tokenizer.js @@ -36,8 +36,6 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter; /** - * - * * Tokenizes the current [[Document `Document`]] in the background, and caches the tokenized rows for future use. * * If a certain row is changed, everything below that row is re-tokenized. @@ -50,8 +48,6 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter; * @param {Tokenizer} tokenizer The tokenizer to use * @param {Editor} editor The editor to associate with * - * - * * @constructor **/ @@ -89,10 +85,9 @@ var BackgroundTokenizer = function(tokenizer, editor) { // only check every 5 lines processedLines ++; - if ((processedLines % 5 == 0) && (new Date() - workerStart) > 20) { + if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) { self.running = setTimeout(self.$worker, 20); - self.currentLine = currentLine; - return; + break; } } self.currentLine = currentLine; From 72dcd289050f0d129139906960dbe822e06eaedc Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 1 Aug 2014 22:06:43 +0400 Subject: [PATCH 3/3] trigger redraw less often --- lib/ace/editor.js | 2 +- lib/ace/virtual_renderer.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index e198ecaa..83782f06 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -702,7 +702,7 @@ var Editor = function(renderer, session) { lastRow = range.end.row; else lastRow = Infinity; - this.renderer.updateLines(range.start.row, lastRow); + this.renderer.updateLines(range.start.row, lastRow, this.session.$useWrapMode); this._signal("change", e); diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index dfb435be..d3e26758 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -258,7 +258,7 @@ var VirtualRenderer = function(container, theme) { * * **/ - this.updateLines = function(firstRow, lastRow) { + this.updateLines = function(firstRow, lastRow, force) { if (lastRow === undefined) lastRow = Infinity; @@ -279,9 +279,13 @@ var VirtualRenderer = function(container, theme) { // If the change happened offscreen above us then it's possible // that a new line wrap will affect the position of the lines on our // screen so they need redrawn. - if (this.$changedLines.lastRow < this.layerConfig.firstRow) - this.$changedLines.lastRow = this.layerConfig.lastRow - + // TODO: better solution is to not change scroll position when text is changed outside of visible area + if (this.$changedLines.lastRow < this.layerConfig.firstRow) { + if (force) + this.$changedLines.lastRow = this.layerConfig.lastRow; + else + return; + } if (this.$changedLines.firstRow > this.layerConfig.lastRow) return; this.$loop.schedule(this.CHANGE_LINES);