🐛 Fix incorrect handling of selected token set

This commit is contained in:
Andrey Antukh 2025-02-11 12:26:46 +01:00
parent b0a6e5c946
commit a029ec18a6
2 changed files with 32 additions and 25 deletions

View file

@ -31,6 +31,8 @@
;; TOKENS Getters ;; TOKENS Getters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FIXME: lookup rename
(defn get-tokens-lib (defn get-tokens-lib
[state] [state]
(-> (dsh/lookup-file-data state) (-> (dsh/lookup-file-data state)
@ -237,32 +239,37 @@
(ptk/reify ::update-create-token (ptk/reify ::update-create-token
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [data (dsh/lookup-file-data state) (let [data (dsh/lookup-file-data state)
token-set (dwts/get-selected-token-set state) selected (dm/get-in state [:workspace-tokens :selected-token-set-name])
set-name (or (:name token-set) "Global")
changes (if (not token-set)
;; No set created add a global set
(let [tokens-lib (get-tokens-lib state)
token-set (ctob/make-token-set :name set-name :tokens {(:name token) token})
hidden-theme (ctob/make-hidden-token-theme :sets [set-name])
active-theme-paths (some-> tokens-lib ctob/get-active-theme-paths)
add-to-hidden-theme? (= active-theme-paths #{ctob/hidden-token-theme-path})
base-changes (pcb/add-token-set (pcb/empty-changes) token-set)]
(cond
(not tokens-lib)
(-> base-changes
(pcb/add-token-theme hidden-theme)
(pcb/update-active-token-themes #{ctob/hidden-token-theme-path} #{}))
add-to-hidden-theme? tokens-lib (get-tokens-lib state)
(let [prev-hidden-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name)] token-set (if selected
(-> base-changes (some-> tokens-lib (ctob/get-set selected))
(pcb/update-token-theme (ctob/toggle-set prev-hidden-theme ctob/hidden-token-theme-path) prev-hidden-theme))) (some-> tokens-lib (ctob/get-sets) (first)))
:else base-changes)) set-name (or (:name token-set) "Global")
(-> (pcb/empty-changes it) changes (if (not token-set)
(pcb/with-library-data data) ;; No set created add a global set
(pcb/set-token set-name (or prev-token-name (:name token)) token)))] (let [token-set (ctob/make-token-set :name set-name :tokens {(:name token) token})
hidden-theme (ctob/make-hidden-token-theme :sets [set-name])
active-theme-paths (some-> tokens-lib ctob/get-active-theme-paths)
add-to-hidden-theme? (= active-theme-paths #{ctob/hidden-token-theme-path})
base-changes (pcb/add-token-set (pcb/empty-changes) token-set)]
(cond
(not tokens-lib)
(-> base-changes
(pcb/add-token-theme hidden-theme)
(pcb/update-active-token-themes #{ctob/hidden-token-theme-path} #{}))
add-to-hidden-theme?
(let [prev-hidden-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name)]
(-> base-changes
(pcb/update-token-theme (ctob/toggle-set prev-hidden-theme ctob/hidden-token-theme-path) prev-hidden-theme)))
:else base-changes))
(-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/set-token set-name (or prev-token-name (:name token)) token)))]
(rx/of (rx/of
(set-selected-token-set-name set-name) (set-selected-token-set-name set-name)

View file

@ -12,7 +12,7 @@
[app.main.data.helpers :as dsh])) [app.main.data.helpers :as dsh]))
(defn get-selected-token-set-name [state] (defn get-selected-token-set-name [state]
(or (get-in state [:workspace-local :selected-token-set-name]) (or (get-in state [:workspace-tokens :selected-token-set-name])
(some-> (dsh/lookup-file-data state) (some-> (dsh/lookup-file-data state)
(get :tokens-lib) (get :tokens-lib)
(ctob/get-sets) (ctob/get-sets)