Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked decorations debounce delay with special exception for scrolling #377

Merged
merged 4 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 28 additions & 14 deletions src/core/HatAllocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export class HatAllocator {
.get<boolean>("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
)
);

Expand All @@ -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.
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
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)
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
)
);
}

Expand All @@ -66,25 +80,25 @@ export class HatAllocator {
}
}

addDecorationsDebounced() {
// Use default debounced delay. 60Hz
addDecorationsDebouncedDefault() {
this.addDecorationsDebounced(16);
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
}

addDecorationsDebounced(decorationDebounceDelay: number) {
if (this.timeoutHandle != null) {
clearTimeout(this.timeoutHandle);
}

const decorationDebounceDelay = vscode.workspace
.getConfiguration("cursorless")
.get<number>("decorationDebounceDelay")!;

this.timeoutHandle = setTimeout(() => {
this.addDecorations();

this.timeoutHandle = null;
}, decorationDebounceDelay);
}

private toggleDecorations() {
this.isActive = !this.isActive;
this.addDecorationsDebounced();
this.addDecorationsDebouncedDefault();
}

dispose() {
Expand Down