From c35f70edc57d7963ebcd737accdc8af3facdf578 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 2 Mar 2026 13:12:40 +0100 Subject: [PATCH] :paperclip: Add minor adjustments --- .../main/ui/workspace/sidebar/layer_item.cljs | 7 +++--- .../main/ui/workspace/sidebar/layer_name.cljs | 23 +++++-------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/layer_item.cljs b/frontend/src/app/main/ui/workspace/sidebar/layer_item.cljs index ea16874955..1a8e5cb43c 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/layer_item.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/layer_item.cljs @@ -423,8 +423,9 @@ on-tab-press (mf/use-fn (mf/deps id objects) - (fn [shift?] - (let [shape (get objects id) + (fn [event] + (let [shift? (kbd/shift? event) + shape (get objects id) parent (get objects (:parent-id shape)) siblings (:shapes parent) pos (d/index-of siblings id)] @@ -435,7 +436,7 @@ (get siblings (inc pos)) (get siblings (dec pos)))] (when (some? target-id) - (st/emit! (dw/start-rename-shape target-id)))))))))] + (st/emit! (dw/start-rename-shape target-id))))))))] (mf/with-effect [is-selected selected] (let [single? (= (count selected) 1) diff --git a/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs b/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs index 550749ed9a..5c0f181c1d 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs @@ -29,12 +29,6 @@ (let [edition* (mf/use-state false) edition? (deref edition*) - ;; Mutable ref to track editing state inside mf/use-fn callbacks. - ;; mf/use-state wraps React useState, so @edition* inside memoized - ;; callbacks captures a stale State object. A ref is a stable mutable - ;; container that always reflects the latest value. - editing-ref (mf/use-ref false) - local-ref (mf/use-ref) ref (d/nilv ref local-ref) @@ -59,19 +53,17 @@ (when (and (not is-blocked) (not disabled-double-click)) (on-start-edit) - (mf/set-ref-val! editing-ref true) (reset! edition* true) (st/emit! (dw/start-rename-shape shape-id))))) accept-edit (mf/use-fn - (mf/deps shape-id on-stop-edit component-id variant-id variant-name variant-properties) + (mf/deps edition? shape-id on-stop-edit component-id variant-id variant-name variant-properties) (fn [] - (when (mf/ref-val editing-ref) + (when edition? (let [name-input (mf/ref-val ref) name (str/trim (dom/get-value name-input))] (on-stop-edit) - (mf/set-ref-val! editing-ref false) (reset! edition* false) (st/emit! (dw/rename-shape-or-variant shape-id name)))))) @@ -80,29 +72,26 @@ (mf/deps shape-id on-stop-edit) (fn [] (on-stop-edit) - (mf/set-ref-val! editing-ref false) (reset! edition* false) (st/emit! (dw/end-rename-shape shape-id nil)))) on-key-down (mf/use-fn - (mf/deps accept-edit cancel-edit on-tab-press shape-id on-stop-edit) + (mf/deps edition? accept-edit cancel-edit on-tab-press shape-id on-stop-edit) (fn [event] (when (kbd/enter? event) (accept-edit)) (when (kbd/esc? event) (cancel-edit)) (when (kbd/tab? event) (dom/prevent-default event) (dom/stop-propagation event) - (when (mf/ref-val editing-ref) - (let [shift? (kbd/shift? event) - name-input (mf/ref-val ref) + (when edition? + (let [name-input (mf/ref-val ref) name (str/trim (dom/get-value name-input))] (on-stop-edit) - (mf/set-ref-val! editing-ref false) (reset! edition* false) (st/emit! (dw/end-rename-shape shape-id name)) (when (fn? on-tab-press) - (on-tab-press shift?))))))) + (on-tab-press event))))))) parent-size (dm/str (- parent-size space-for-icons) "px")]