Skip to content

Commit

Permalink
keyboard shortcuts: fix setting of data-key attr
Browse files Browse the repository at this point in the history
When multiple keyboard shortcut actions were set on an element (like in
the chart switcher for previous and next), the data-key element would be
removed by the second one even if the first one set a shortcut.
  • Loading branch information
yagebu committed Jan 6, 2024
1 parent b35317b commit a438948
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions frontend/src/keyboard-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,25 @@ export const keyboardShortcut: Action<HTMLElement, KeySpec | undefined> = (
const setup = (s?: KeySpec) => {
if (s) {
node.setAttribute("data-key", getKeySpecDescription(s));
return bindKey(s, node);
const unbind = bindKey(s, node);
return () => {
unbind();
node.removeAttribute("data-key");
};
}
node.removeAttribute("data-key");
return () => {};
};
let unbind = setup(spec);
let destroy = setup(spec);

return {
destroy: unbind,
destroy,
update(new_spec) {
unbind();
destroy();
// Await tick so that key bindings that might have been removed from other
// elements in the same render are gone.
tick()
.then(() => {
unbind = setup(new_spec);
destroy = setup(new_spec);
})
.catch(log_error);
},
Expand Down

0 comments on commit a438948

Please sign in to comment.