Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions src/lib/KeyboardShortcutsPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,27 @@ export default class KeyboardShortcutsManager {
}

try {
// Save each shortcut as a separate config entry
// Save or delete each shortcut depending on whether it matches the default
const promises = [];
for (const [shortcutName, value] of Object.entries(shortcuts)) {
const key = `settings.keyboard.binding.${shortcutName}`;
promises.push(this.serverStorage.setConfig(key, value, appId));
const defaultValue = DEFAULT_SHORTCUTS[shortcutName];

// Check if the value matches the default (compare key and modifiers)
const isDefault = defaultValue && value &&
value.key?.toLowerCase() === defaultValue.key?.toLowerCase() &&
!!value.ctrl === !!defaultValue.ctrl &&
!!value.shift === !!defaultValue.shift &&
!!value.alt === !!defaultValue.alt &&
!!value.meta === !!defaultValue.meta;

if (isDefault) {
// Delete the entry if it matches the default (no need to store it)
promises.push(this.serverStorage.deleteConfig(key, appId));
} else {
// Save the entry if it differs from the default
promises.push(this.serverStorage.setConfig(key, value, appId));
}
}

await Promise.all(promises);
Expand All @@ -104,12 +120,27 @@ export default class KeyboardShortcutsManager {
}

/**
* Resets keyboard shortcuts to defaults
* Resets keyboard shortcuts to defaults by deleting stored entries
* @param {string} appId - The application ID
* @returns {Promise}
*/
async resetKeyboardShortcuts(appId) {
return this.saveKeyboardShortcuts(appId, DEFAULT_SHORTCUTS);
if (!this.serverStorage.isServerConfigEnabled()) {
return; // Nothing to delete if server config is not enabled
}

try {
// Delete all keyboard shortcut entries so defaults will be used
const promises = [];
for (const shortcutName of Object.keys(DEFAULT_SHORTCUTS)) {
const key = `settings.keyboard.binding.${shortcutName}`;
promises.push(this.serverStorage.deleteConfig(key, appId));
}
await Promise.all(promises);
} catch (error) {
console.error('Failed to reset keyboard shortcuts:', error);
throw error;
}
}

/**
Expand Down
Loading