Skip to content

Commit d955334

Browse files
committed
Update color decorator debounce
1 parent 8b03e8b commit d955334

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
},
174174
"devDependencies": {
175175
"@ctrl/tinycolor": "^3.1.0",
176+
"@types/debounce": "^1.2.0",
176177
"@types/mocha": "^5.2.0",
177178
"@types/moo": "^0.5.3",
178179
"@types/node": "^13.9.3",
@@ -182,6 +183,7 @@
182183
"chokidar": "^3.3.1",
183184
"concurrently": "^5.1.0",
184185
"css.escape": "^1.5.1",
186+
"debounce": "^1.2.0",
185187
"detect-indent": "^6.0.0",
186188
"dlv": "^1.1.3",
187189
"dset": "^2.0.1",

src/lib/registerColorDecorator.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { window, workspace, ExtensionContext, TextEditor } from 'vscode'
22
import { NotificationEmitter } from './emitter'
33
import { LanguageClient } from 'vscode-languageclient'
4+
import debounce from 'debounce'
45

56
const colorDecorationType = window.createTextEditorDecorationType({
67
before: {
@@ -28,7 +29,6 @@ export function registerColorDecorator(
2829
emitter: NotificationEmitter
2930
) {
3031
let activeEditor = window.activeTextEditor
31-
let timeout: NodeJS.Timer | undefined = undefined
3232

3333
async function updateDecorations() {
3434
return updateDecorationsInEditor(activeEditor)
@@ -76,13 +76,7 @@ export function registerColorDecorator(
7676
)
7777
}
7878

79-
function triggerUpdateDecorations() {
80-
if (timeout) {
81-
clearTimeout(timeout)
82-
timeout = undefined
83-
}
84-
timeout = setTimeout(updateDecorations, 500)
85-
}
79+
const triggerUpdateDecorations = debounce(updateDecorations, 200)
8680

8781
if (activeEditor) {
8882
triggerUpdateDecorations()

0 commit comments

Comments
 (0)