mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-13 00:41:59 +03:00
Added shortcut input controls to make custom shortcuts work
This commit is contained in:
@ -30,13 +30,7 @@ class Shortcuts {
|
||||
return;
|
||||
}
|
||||
|
||||
const shortcutId = this.mapByShortcut[event.key];
|
||||
if (shortcutId) {
|
||||
const wasHandled = this.runShortcut(shortcutId);
|
||||
if (wasHandled) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
this.handleShortcutPress(event);
|
||||
});
|
||||
|
||||
window.addEventListener('keydown', event => {
|
||||
@ -46,6 +40,28 @@ class Shortcuts {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
handleShortcutPress(event) {
|
||||
|
||||
const keys = [
|
||||
event.ctrlKey ? 'Ctrl' : '',
|
||||
event.metaKey ? 'Cmd' : '',
|
||||
event.key,
|
||||
];
|
||||
|
||||
const combo = keys.filter(s => Boolean(s)).join(' + ');
|
||||
|
||||
const shortcutId = this.mapByShortcut[combo];
|
||||
if (shortcutId) {
|
||||
const wasHandled = this.runShortcut(shortcutId);
|
||||
if (wasHandled) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given shortcut, and return a boolean to indicate if the event
|
||||
* was successfully handled by a shortcut action.
|
||||
|
Reference in New Issue
Block a user