Skip to content

Commit

Permalink
Add a timeout for keybinding hold
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Mar 18, 2024
1 parent 198250f commit c5c0a9c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/commands/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,17 @@ export class CommandRegistry {
if (this._holdKeyBindingPromises.size !== 0) {
// Wait until all hold requests on execution are lifted.
const executionAllowed = (
await Promise.all(
this._keydownEvents.map(
async event =>
this._holdKeyBindingPromises.get(event) ?? Promise.resolve(true)
)
)
await Promise.race([
Promise.all(
this._keydownEvents.map(
async event =>
this._holdKeyBindingPromises.get(event) ?? Promise.resolve(true)
)
),
new Promise<boolean[]>(resolve => {
setTimeout(() => resolve([false]), Private.KEYBINDING_HOLD_TIMEOUT);
})
])
).every(Boolean);
// Clear the hold requests.
this._holdKeyBindingPromises.clear();
Expand Down Expand Up @@ -1350,6 +1355,11 @@ namespace Private {
*/
export const CHORD_TIMEOUT = 1000;

/**
* The timeout in ms for stopping the hold on keybinding execution.
*/
export const KEYBINDING_HOLD_TIMEOUT = 1000;

/**
* A convenience type alias for a command func.
*/
Expand Down

0 comments on commit c5c0a9c

Please sign in to comment.