Skip to content

Commit

Permalink
Merge pull request #535 from memeplex/main
Browse files Browse the repository at this point in the history
Don't delay decorations on editor activation
  • Loading branch information
alexdima committed Dec 3, 2021
2 parents 598e911 + 2098ec0 commit ea1dafa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions decorator-sample/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ export function activate(context: vscode.ExtensionContext) {
activeEditor.setDecorations(largeNumberDecorationType, largeNumbers);
}

function triggerUpdateDecorations() {
function triggerUpdateDecorations(throttle: boolean = false) {
if (timeout) {
clearTimeout(timeout);
timeout = undefined;
}
timeout = setTimeout(updateDecorations, 500);
if (throttle) {
timeout = setTimeout(updateDecorations, 500);
} else {
updateDecorations();
}
}

if (activeEditor) {
Expand All @@ -76,7 +80,7 @@ export function activate(context: vscode.ExtensionContext) {

vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
triggerUpdateDecorations();
triggerUpdateDecorations(true);
}
}, null, context.subscriptions);

Expand Down

0 comments on commit ea1dafa

Please sign in to comment.