Update color decorator debounce

master
Brad Cornes 2020-08-21 13:44:24 +01:00
parent 8b03e8b984
commit d95533428f
3 changed files with 16 additions and 8 deletions

12
package-lock.json generated
View File

@ -1019,6 +1019,12 @@
"integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==",
"dev": true
},
"@types/debounce": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@types/debounce/-/debounce-1.2.0.tgz",
"integrity": "sha512-bWG5wapaWgbss9E238T0R6bfo5Fh3OkeoSt245CM7JJwVwpw6MEBCbIxLq5z8KzsE3uJhzcIuQkyiZmzV3M/Dw==",
"dev": true
},
"@types/graceful-fs": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.3.tgz",
@ -1960,6 +1966,12 @@
"integrity": "sha512-8P1cDi8ebZyDxUyUprBXwidoEtiQAawYPGvpfb+Dg0G6JrQ+VozwOmm91xYC0vAv1+0VmLehEPb+isg4BGUFfA==",
"dev": true
},
"debounce": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.0.tgz",
"integrity": "sha512-mYtLl1xfZLi1m4RtQYlZgJUNQjl4ZxVnHzIR8nLLgi4q1YT8o/WM+MK/f8yfcc9s5Ir5zRaPZyZU6xs1Syoocg==",
"dev": true
},
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",

View File

@ -173,6 +173,7 @@
},
"devDependencies": {
"@ctrl/tinycolor": "^3.1.0",
"@types/debounce": "^1.2.0",
"@types/mocha": "^5.2.0",
"@types/moo": "^0.5.3",
"@types/node": "^13.9.3",
@ -182,6 +183,7 @@
"chokidar": "^3.3.1",
"concurrently": "^5.1.0",
"css.escape": "^1.5.1",
"debounce": "^1.2.0",
"detect-indent": "^6.0.0",
"dlv": "^1.1.3",
"dset": "^2.0.1",

View File

@ -1,6 +1,7 @@
import { window, workspace, ExtensionContext, TextEditor } from 'vscode'
import { NotificationEmitter } from './emitter'
import { LanguageClient } from 'vscode-languageclient'
import debounce from 'debounce'
const colorDecorationType = window.createTextEditorDecorationType({
before: {
@ -28,7 +29,6 @@ export function registerColorDecorator(
emitter: NotificationEmitter
) {
let activeEditor = window.activeTextEditor
let timeout: NodeJS.Timer | undefined = undefined
async function updateDecorations() {
return updateDecorationsInEditor(activeEditor)
@ -76,13 +76,7 @@ export function registerColorDecorator(
)
}
function triggerUpdateDecorations() {
if (timeout) {
clearTimeout(timeout)
timeout = undefined
}
timeout = setTimeout(updateDecorations, 500)
}
const triggerUpdateDecorations = debounce(updateDecorations, 200)
if (activeEditor) {
triggerUpdateDecorations()