Skip to content

Commit

Permalink
Throttle validateSelections execution.
Browse files Browse the repository at this point in the history
  • Loading branch information
aioutecism committed Jun 6, 2016
1 parent 280b5ce commit 6058616
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export class Dispatcher {
ActionMode.switchByActiveSelections(this.currentMode.id);
ActionMoveCursor.updatePreferedCharacter();
// Delay validate execution until other actions complete.
setTimeout(() => ActionSelection.validateSelections());
this.validateSelections();
}),
window.onDidChangeActiveTextEditor(() => {
ActionMode.switchByActiveSelections(this.currentMode.id);
ActionMoveCursor.updatePreferedCharacter();
// Delay validate execution until other actions complete.
setTimeout(() => ActionSelection.validateSelections());
this.validateSelections();
})
);
}
Expand Down Expand Up @@ -94,6 +94,18 @@ export class Dispatcher {
}
}

private validateSelectionsTimer: number;
private validateSelections(): void {
if (this.validateSelectionsTimer !== undefined) {
clearTimeout(this.validateSelectionsTimer);
}

this.validateSelectionsTimer = setTimeout(() => {
ActionSelection.validateSelections();
this.validateSelectionsTimer = undefined;
}, 10);
}

dispose(): void {
Disposable.from(...this.disposables).dispose();

Expand Down

0 comments on commit 6058616

Please sign in to comment.