From bbbf5a534c17e35fa88d8750877448efc736cc6f Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Wed, 5 Aug 2026 09:28:07 +0200 Subject: [PATCH] :bug: Fix importing conflicts --- .../src/app/main/ui/settings/shortcuts.cljs | 16 ++++++++++---- frontend/src/app/main/ui/shortcuts.cljs | 21 ++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/ui/settings/shortcuts.cljs b/frontend/src/app/main/ui/settings/shortcuts.cljs index 7800403adc..7534b57ea9 100644 --- a/frontend/src/app/main/ui/settings/shortcuts.cljs +++ b/frontend/src/app/main/ui/settings/shortcuts.cljs @@ -93,10 +93,18 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (def ^:private known-shortcut-keys - "Known shortcut keys per context, derived from the default shortcuts maps." - {:workspace (set (keys wsc/shortcuts)) - :dashboard (set (keys dsc/shortcuts)) - :viewer (set (keys vsc/shortcuts))}) + "Known shortcut keys per context, derived from the default shortcuts maps. + Shortcuts marked :customizable false are excluded." + (letfn [(collect-keys [shortcuts] + (reduce-kv (fn [s k v] + (if (false? (:customizable v)) + s + (conj s k))) + #{} + shortcuts))] + {:workspace (into (collect-keys psc/shortcuts) (collect-keys wsc/shortcuts)) + :dashboard (collect-keys dsc/shortcuts) + :viewer (collect-keys vsc/shortcuts)})) (def ^:private schema:imported-shortcuts "Malli schema for an imported custom-shortcuts payload. diff --git a/frontend/src/app/main/ui/shortcuts.cljs b/frontend/src/app/main/ui/shortcuts.cljs index 4499eac9ed..5db911b625 100644 --- a/frontend/src/app/main/ui/shortcuts.cljs +++ b/frontend/src/app/main/ui/shortcuts.cljs @@ -10,9 +10,13 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.config :as cf] + [app.main.data.dashboard.shortcuts :as dsc] [app.main.data.dashboard.shortcuts.customize :as customize] [app.main.data.profile :as du] [app.main.data.shortcuts :as ds] + [app.main.data.viewer.shortcuts :as vsc] + [app.main.data.workspace.path.shortcuts :as psc] + [app.main.data.workspace.shortcuts :as wsc] [app.main.store :as st] [app.main.ui.context :as ctx] [app.main.ui.ds.buttons.icon-button :refer [icon-button*]] @@ -107,14 +111,24 @@ (def ^:private import-contexts [:workspace :dashboard :viewer]) +(def ^:private context->known-keys + {:workspace (into #{} (concat (keys psc/shortcuts) (keys wsc/shortcuts))) + :dashboard (into #{} (keys dsc/shortcuts)) + :viewer (into #{} (keys vsc/shortcuts))}) + +(defn- build-context-shortcuts + [all-shortcuts ctx] + (let [known-keys (get context->known-keys ctx)] + (into {} (filter (fn [[k _]] (contains? known-keys k))) all-shortcuts))) + (defn- import-context-group "Imports a single context group from the payload, disabling any default shortcut whose command collides with a newly imported one, and any previously-imported entry in the same batch with a duplicate command." - [group all-shortcuts] + [group context-shortcuts] (reduce (fn [acc [command recorded-command]] - (let [default-conflict (find-conflict recorded-command all-shortcuts command) + (let [default-conflict (find-conflict recorded-command context-shortcuts command) acc-conflict (some (fn [[k v]] (when (and (not= k command) (= v recorded-command)) k)) @@ -136,7 +150,8 @@ new-customs (reduce (fn [acc ctx] (if (contains? shortcuts ctx) - (assoc acc ctx (import-context-group (get shortcuts ctx) all-shortcuts)) + (let [ctx-sc (build-context-shortcuts all-shortcuts ctx)] + (assoc acc ctx (import-context-group (get shortcuts ctx) ctx-sc))) acc)) current-customs import-contexts)]