Skip to content

Commit

Permalink
Remove highlight flickering on init
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marijnh committed Jan 24, 2024
1 parent ade6caa commit 48d2f7f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 48d2f7f

Please sign in to comment.