🐛 Fix importing conflicts

This commit is contained in:
Eva Marco 2026-08-05 09:28:07 +02:00
parent c2017b83dc
commit bbbf5a534c
2 changed files with 30 additions and 7 deletions

View File

@ -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.

View File

@ -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)]