mirror of
https://github.com/penpot/penpot.git
synced 2026-08-18 10:48:35 +00:00
🐛 Fix importing conflicts
This commit is contained in:
parent
c2017b83dc
commit
bbbf5a534c
@ -93,10 +93,18 @@
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(def ^:private known-shortcut-keys
|
(def ^:private known-shortcut-keys
|
||||||
"Known shortcut keys per context, derived from the default shortcuts maps."
|
"Known shortcut keys per context, derived from the default shortcuts maps.
|
||||||
{:workspace (set (keys wsc/shortcuts))
|
Shortcuts marked :customizable false are excluded."
|
||||||
:dashboard (set (keys dsc/shortcuts))
|
(letfn [(collect-keys [shortcuts]
|
||||||
:viewer (set (keys vsc/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
|
(def ^:private schema:imported-shortcuts
|
||||||
"Malli schema for an imported custom-shortcuts payload.
|
"Malli schema for an imported custom-shortcuts payload.
|
||||||
|
|||||||
@ -10,9 +10,13 @@
|
|||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
|
[app.main.data.dashboard.shortcuts :as dsc]
|
||||||
[app.main.data.dashboard.shortcuts.customize :as customize]
|
[app.main.data.dashboard.shortcuts.customize :as customize]
|
||||||
[app.main.data.profile :as du]
|
[app.main.data.profile :as du]
|
||||||
[app.main.data.shortcuts :as ds]
|
[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.store :as st]
|
||||||
[app.main.ui.context :as ctx]
|
[app.main.ui.context :as ctx]
|
||||||
[app.main.ui.ds.buttons.icon-button :refer [icon-button*]]
|
[app.main.ui.ds.buttons.icon-button :refer [icon-button*]]
|
||||||
@ -107,14 +111,24 @@
|
|||||||
(def ^:private import-contexts
|
(def ^:private import-contexts
|
||||||
[:workspace :dashboard :viewer])
|
[: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
|
(defn- import-context-group
|
||||||
"Imports a single context group from the payload, disabling any default
|
"Imports a single context group from the payload, disabling any default
|
||||||
shortcut whose command collides with a newly imported one, and any
|
shortcut whose command collides with a newly imported one, and any
|
||||||
previously-imported entry in the same batch with a duplicate command."
|
previously-imported entry in the same batch with a duplicate command."
|
||||||
[group all-shortcuts]
|
[group context-shortcuts]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [acc [command recorded-command]]
|
(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]]
|
acc-conflict (some (fn [[k v]]
|
||||||
(when (and (not= k command) (= v recorded-command))
|
(when (and (not= k command) (= v recorded-command))
|
||||||
k))
|
k))
|
||||||
@ -136,7 +150,8 @@
|
|||||||
new-customs (reduce
|
new-customs (reduce
|
||||||
(fn [acc ctx]
|
(fn [acc ctx]
|
||||||
(if (contains? shortcuts 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))
|
acc))
|
||||||
current-customs
|
current-customs
|
||||||
import-contexts)]
|
import-contexts)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user