From b437034a0b8fdfa323c683be4cc18fb5e4b5d92d Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 11 Dec 2021 12:47:08 +0100 Subject: [PATCH 1/2] Reworked decorations debounce delay with special exception for scrolling --- package.json | 7 +------ src/core/HatAllocator.ts | 42 ++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 0cf02ee4c5..6e54419d0d 100644 --- a/package.json +++ b/package.json @@ -114,11 +114,6 @@ "default": 100, "description": "How long in milliseconds to show a pending edit decoration" }, - "cursorless.decorationDebounceDelay": { - "type": "integer", - "default": 175, - "description": "How long in milliseconds to wait to redraw the hats after an action" - }, "cursorless.hatSizeAdjustment": { "type": "number", "default": 0, @@ -407,7 +402,7 @@ } } }, - "languages": [ + "languages": [ { "id": "json", "extensions": [ diff --git a/src/core/HatAllocator.ts b/src/core/HatAllocator.ts index b5119ad1ab..4d33f8fca7 100644 --- a/src/core/HatAllocator.ts +++ b/src/core/HatAllocator.ts @@ -22,12 +22,14 @@ export class HatAllocator { .get("showOnStart")!; this.addDecorationsDebounced = this.addDecorationsDebounced.bind(this); + this.addDecorationsDebouncedDefault = + this.addDecorationsDebouncedDefault.bind(this); this.toggleDecorations = this.toggleDecorations.bind(this); this.clearEditorDecorations = this.clearEditorDecorations.bind(this); this.disposalFunctions.push( graph.decorations.registerDecorationChangeListener( - this.addDecorationsDebounced + this.addDecorationsDebouncedDefault ) ); @@ -37,15 +39,27 @@ export class HatAllocator { this.toggleDecorations ), - vscode.window.onDidChangeTextEditorVisibleRanges( - this.addDecorationsDebounced + // An Event which fires when the active editor has changed. Note that the event also fires when the active editor changes to undefined. + vscode.window.onDidChangeActiveTextEditor( + this.addDecorationsDebouncedDefault ), - vscode.window.onDidChangeActiveTextEditor(this.addDecorationsDebounced), - vscode.window.onDidChangeVisibleTextEditors(this.addDecorationsDebounced), + // An Event which fires when the array of visible editors has changed. + vscode.window.onDidChangeVisibleTextEditors( + this.addDecorationsDebouncedDefault + ), + // An event that is emitted when a text document is changed. This usually happens when the contents changes but also when other things like the dirty-state changes. + vscode.workspace.onDidChangeTextDocument( + this.addDecorationsDebouncedDefault + ), + // An Event which fires when the selection in an editor has changed. vscode.window.onDidChangeTextEditorSelection( - this.addDecorationsDebounced + this.addDecorationsDebouncedDefault ), - vscode.workspace.onDidChangeTextDocument(this.addDecorationsDebounced) + // An Event which fires when the visible ranges of an editor has changed. + vscode.window.onDidChangeTextEditorVisibleRanges(() => + // Increase debounced delay to stop the decorations moving when scrolling. 25Hz + this.addDecorationsDebounced(40) + ) ); } @@ -66,25 +80,25 @@ export class HatAllocator { } } - addDecorationsDebounced() { + // Use default debounced delay. 60Hz + addDecorationsDebouncedDefault() { + this.addDecorationsDebounced(16); + } + + addDecorationsDebounced(decorationDebounceDelay: number) { if (this.timeoutHandle != null) { clearTimeout(this.timeoutHandle); } - const decorationDebounceDelay = vscode.workspace - .getConfiguration("cursorless") - .get("decorationDebounceDelay")!; - this.timeoutHandle = setTimeout(() => { this.addDecorations(); - this.timeoutHandle = null; }, decorationDebounceDelay); } private toggleDecorations() { this.isActive = !this.isActive; - this.addDecorationsDebounced(); + this.addDecorationsDebouncedDefault(); } dispose() { From 09253af15d4f5431733ad0b66bf2598eb87f54bb Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 11 Dec 2021 12:51:02 +0100 Subject: [PATCH 2/2] Restore indentation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e54419d0d..53da3b9465 100644 --- a/package.json +++ b/package.json @@ -402,7 +402,7 @@ } } }, - "languages": [ + "languages": [ { "id": "json", "extensions": [