Skip to content

Commit

Permalink
Try to fix unreliable keybinds.
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanvugt committed Oct 13, 2023
1 parent 16c3c5f commit 68fa438
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/actions/keybind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ type Options = {
};

export function keybind(node: HTMLElement, options: Options) {
const mousetrap = new Mousestrap(document.getElementsByTagName("main")[0]);
console.debug("[keybind] binding:", options.keys);

const mousetrap = new Mousestrap(document.documentElement);
mousetrap.bind(options.keys, () => {
console.debug("[keybind] handling:", options.keys);
options.f();

// Always prevent default behavior
Expand All @@ -16,6 +19,7 @@ export function keybind(node: HTMLElement, options: Options) {

return {
destroy() {
console.debug("[keybind] destorying:", options.keys);
mousetrap.reset();
}
};
Expand Down

0 comments on commit 68fa438

Please sign in to comment.