mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 15:49:00 +02:00
refactor(hotkeys): simplify normalization
This commit is contained in:
parent
eb805bfa2a
commit
5d00630452
@ -101,11 +101,14 @@ function matchesShortcut(e: KeyboardEvent, shortcut: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function keyMatches(e: KeyboardEvent, key: string): boolean {
|
function keyMatches(e: KeyboardEvent, key: string): boolean {
|
||||||
// Handle special key mappings
|
// Handle special key mappings and aliases
|
||||||
const keyMap: { [key: string]: string[] } = {
|
const keyMap: { [key: string]: string[] } = {
|
||||||
'return': ['Enter'],
|
'return': ['Enter'],
|
||||||
|
'enter': ['Enter'], // alias for return
|
||||||
'del': ['Delete'],
|
'del': ['Delete'],
|
||||||
|
'delete': ['Delete'], // alias for del
|
||||||
'esc': ['Escape'],
|
'esc': ['Escape'],
|
||||||
|
'escape': ['Escape'], // alias for esc
|
||||||
'space': [' ', 'Space'],
|
'space': [' ', 'Space'],
|
||||||
'tab': ['Tab'],
|
'tab': ['Tab'],
|
||||||
'backspace': ['Backspace'],
|
'backspace': ['Backspace'],
|
||||||
@ -135,32 +138,14 @@ function keyMatches(e: KeyboardEvent, key: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize to a consistent format for our custom shortcut parser
|
* Simple normalization - just lowercase and trim whitespace
|
||||||
*/
|
*/
|
||||||
function normalizeShortcut(shortcut: string): string {
|
function normalizeShortcut(shortcut: string): string {
|
||||||
if (!shortcut) {
|
if (!shortcut) {
|
||||||
return shortcut;
|
return shortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shortcut
|
return shortcut.toLowerCase().trim().replace(/\s+/g, '');
|
||||||
.toLowerCase()
|
|
||||||
.trim()
|
|
||||||
.replace(/\s+/g, '') // Remove any spaces
|
|
||||||
.replace("enter", "return")
|
|
||||||
.replace("delete", "del")
|
|
||||||
.replace("escape", "esc")
|
|
||||||
// Normalize modifier order: ctrl, alt, shift, meta, then key
|
|
||||||
.split('+')
|
|
||||||
.sort((a, b) => {
|
|
||||||
const order = ['ctrl', 'control', 'alt', 'shift', 'meta', 'cmd', 'command'];
|
|
||||||
const aIndex = order.indexOf(a);
|
|
||||||
const bIndex = order.indexOf(b);
|
|
||||||
if (aIndex === -1 && bIndex === -1) return 0;
|
|
||||||
if (aIndex === -1) return 1;
|
|
||||||
if (bIndex === -1) return -1;
|
|
||||||
return aIndex - bIndex;
|
|
||||||
})
|
|
||||||
.join('+');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user