From d9fc1e81cd24f04ea16460e8b56a627b340eda38 Mon Sep 17 00:00:00 2001 From: "mr. M" Date: Tue, 4 Feb 2025 19:26:04 +0100 Subject: [PATCH] Implement default keyboard shortcuts filling and migration handling --- .../base/zen-components/ZenKeyboardShortcuts.mjs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/browser/base/zen-components/ZenKeyboardShortcuts.mjs b/src/browser/base/zen-components/ZenKeyboardShortcuts.mjs index 342c5d68c..986dd3d26 100644 --- a/src/browser/base/zen-components/ZenKeyboardShortcuts.mjs +++ b/src/browser/base/zen-components/ZenKeyboardShortcuts.mjs @@ -810,6 +810,20 @@ class ZenKeyboardShortcutsVersioner { return this.migrateIfNeeded(data); } + fillDefaultIfNotPresent(data) { + for (let shortcut of ZenKeyboardShortcutsLoader.zenGetDefaultShortcuts()) { + // If it has an ID and we dont find it in the data, we add it + if (shortcut.getID() && !data.find((s) => s.getID() == shortcut.getID())) { + data.push(shortcut); + } + } + return data; + } + + fixedKeyboardShortcuts(data) { + return this.fillDefaultIfNotPresent(this.migrateIfNeeded(data)); + } + migrate(data, version) { if (version < 1) { // Migrate from 0 to 1 @@ -950,7 +964,7 @@ var gZenKeyboardShortcutsManager = { if (this.inBrowserView) { const loadedShortcuts = await this._loadSaved(); - this._currentShortcutList = this.versioner.migrateIfNeeded(loadedShortcuts); + this._currentShortcutList = this.versioner.fixedKeyboardShortcuts(loadedShortcuts); this._applyShortcuts(); await this._saveShortcuts();