From 48d2f7f41461bf45647fd8969492ce9b2a507cb1 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 24 Jan 2024 18:28:08 +0100 Subject: [PATCH] Remove highlight flickering on init FIX: Fix an issue where, when a lot of code is visible in the initial editor, the bottom bit of code is shown without highlighting for one frame. --- src/highlight.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/highlight.ts b/src/highlight.ts index 905a7e2..84dcea1 100644 --- a/src/highlight.ts +++ b/src/highlight.ts @@ -154,22 +154,27 @@ export interface TagStyle { class TreeHighlighter { decorations: DecorationSet + decoratedTo: number tree: Tree markCache: {[cls: string]: Decoration} = Object.create(null) constructor(view: EditorView) { this.tree = syntaxTree(view.state) this.decorations = this.buildDeco(view, getHighlighters(view.state)) + this.decoratedTo = view.viewport.to } update(update: ViewUpdate) { let tree = syntaxTree(update.state), highlighters = getHighlighters(update.state) let styleChange = highlighters != getHighlighters(update.startState) - if (tree.length < update.view.viewport.to && !styleChange && tree.type == this.tree.type) { + let {viewport} = update.view, decoratedToMapped = update.changes.mapPos(this.decoratedTo, 1) + if (tree.length < viewport.to && !styleChange && tree.type == this.tree.type && decoratedToMapped >= viewport.to) { this.decorations = this.decorations.map(update.changes) + this.decoratedTo = decoratedToMapped } else if (tree != this.tree || update.viewportChanged || styleChange) { this.tree = tree this.decorations = this.buildDeco(update.view, highlighters) + this.decoratedTo = viewport.to } }