feat: enhance keybinding import validation and improve error handling

This commit is contained in:
Anwarul Islam
2025-07-18 08:30:42 +06:00
parent 8e4661951d
commit c3caefc001
3 changed files with 31 additions and 12 deletions
+8
View File
@@ -112,6 +112,13 @@ export const useKeybindingsStore = create<KeybindingsState>()(
},
importKeybindings: (config: KeybindingConfig) => {
// Validate all keys and actions
for (const [key, action] of Object.entries(config)) {
// Validate the key format
if (typeof key !== "string" || key.length === 0) {
throw new Error(`Invalid key format: ${key}`);
}
}
set({
keybindings: { ...config },
isCustomized: true,
@@ -198,6 +205,7 @@ function getPressedKey(ev: KeyboardEvent): string | null {
// Check for special keys
if (key === "tab") return "tab";
if (key === " " || key === "space") return "space";
if (key === "home") return "home";
if (key === "end") return "end";
if (key === "delete") return "delete";