Skip to content

Commit

Permalink
♻️ Refactors removal of text decorations to occur after recoloring
Browse files Browse the repository at this point in the history
This fixes a bug related to flickering when clicking a previously-colored text editor window.

#2
  • Loading branch information
Sawtaytoes committed Nov 21, 2023
1 parent e0812e3 commit bbf720d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 76 deletions.
20 changes: 16 additions & 4 deletions src/colorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
rangesByName,
} from './rangesByName'
import {
removePreviousTextEditorDecorations,
} from './removePreviousTextEditorDecorations'
removeTextEditorDecorations,
} from './removeTextEditorDecorations'
import {
getScopeName,
} from './textMateGrammars'
Expand Down Expand Up @@ -403,8 +403,11 @@ export const colorize = async (
]))
)

removePreviousTextEditorDecorations(
editor
const previousTextEditorDecorations = (
textEditorDecorationMap
.get(
editor
)
)

const textEditorDecorations = (
Expand Down Expand Up @@ -452,4 +455,13 @@ export const colorize = async (
ranges,
)
})

removeTextEditorDecorations(
previousTextEditorDecorations
|| (
new Set<
TextEditorDecorationType
>()
)
)
}
22 changes: 15 additions & 7 deletions src/removeAllTextEditorDecorations.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import {
textEditorDecorationMap,
} from './cache'
import { removePreviousTextEditorDecorations } from './removePreviousTextEditorDecorations'
import {
removeTextEditorDecorations,
} from './removeTextEditorDecorations'

export const removeAllTextEditorDecorations = () => {
Array
.from(
textEditorDecorationMap
.keys()
.entries()
)
.forEach((
editor,
) => {
removePreviousTextEditorDecorations(
editor
.forEach(([
textEditor,
textEditorDecorations,
]) => {
removeTextEditorDecorations(
textEditorDecorations
)

textEditorDecorationMap
.delete(
textEditor
)
})
}
65 changes: 0 additions & 65 deletions src/removePreviousTextEditorDecorations.ts

This file was deleted.

22 changes: 22 additions & 0 deletions src/removeTextEditorDecorations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
TextEditorDecorationType,
} from 'vscode'

export const removeTextEditorDecorations = (
textEditorDecorations: (
Set<
TextEditorDecorationType
>
),
) => {
Array
.from(
textEditorDecorations
)
.forEach((
textEditorDecoration,
) => {
textEditorDecoration
.dispose()
})
}

0 comments on commit bbf720d

Please sign in to comment.