feat: make shortcuts easier to add across the app

This commit is contained in:
Zoe
2026-02-25 19:47:33 -06:00
parent 50cb195486
commit d22d08e99f
4 changed files with 57 additions and 21 deletions
+12 -5
View File
@@ -107,13 +107,20 @@ const handleKeyDown = async (event: KeyboardEvent) => {
};
const handleWindowKeyDown = async (event: KeyboardEvent) => {
if (event.ctrlKey || event.metaKey) {
return;
}
if (event.defaultPrevented) return;
if (event.ctrlKey || event.metaKey || event.altKey) return;
if (document.activeElement === document.body) {
// redirect all standard keyboard input to the input field
inputRef.value?.focus();
const isPrintable = event.key.length === 1;
if (isPrintable) {
inputRef.value?.focus();
} else if (event.key === 'Enter') {
event.preventDefault();
handleSubmit();
inputRef.value?.focus();
}
}
};
+7 -1
View File
@@ -4,7 +4,12 @@ import Settings from './Settings.vue';
import { DialogType } from '~/composables/useDialog';
const { open, page, data, close, confirm } = useDialog();
const { open, page, data, close, confirm, openDialog } = useDialog();
const { addShortcut } = useKeyboardShortcuts();
const unbindShortcut = addShortcut(['ctrl', ','], () => {
openDialog(DialogType.Settings);
});
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
@@ -24,6 +29,7 @@ onUnmounted(() => {
if (open.value) {
document.body.removeEventListener('keydown', handleKeyDown);
}
unbindShortcut();
});
</script>