From 10388a6b77d606e99f80608fb2b329483c901b52 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 24 Nov 2026 19:40:54 +0100 Subject: [PATCH] :bug: Hide the Selected text group once text edit mode ends Pressing Escape in the text editor with the language options open left the "Selected text" group on screen. Leaving edit mode renders the options again while the WASM editor still holds its selection: the editor component disposes it later, when it unmounts, and nothing renders the options after that unless the text changed. The WASM selection now only counts while the store still has the text in edit mode, which Escape clears first. AI-assisted-by: claude-opus-5-5 --- .../ui/workspace/sidebar/options/shapes/text.cljs | 14 ++++++++++++-- .../test/frontend_tests/ui/text_options_test.cljs | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs index 50c26ef2dd..463115531d 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs @@ -53,6 +53,17 @@ (let [selection (.getSelection editor-state)] (and selection (not (.isCollapsed selection)))))) +(defn wasm-text-range-selected? + "True when the WASM editor of the text `id`, in edit mode as `edition` + says, has a range of text selected. Leaving edit mode renders the panel + again before the editor unmounts and disposes the WASM editor, and + nothing renders it after: the edition, cleared first, decides." + [id edition] + (boolean + (and (= id edition) + (= id (wasm.api/text-editor-get-active-shape-id)) + (wasm.api/text-editor-has-selection?)))) + (mf/defc options* [{:keys [shape libraries file-id page-id]}] (let [id (dm/get-prop shape :id) @@ -169,8 +180,7 @@ (boolean (cond text-editor-wasm? - (and (= id (wasm.api/text-editor-get-active-shape-id)) - (wasm.api/text-editor-has-selection?)) + (wasm-text-range-selected? id edition) text-editor-v2? (dom-text-range-selected? editor-instance) diff --git a/frontend/test/frontend_tests/ui/text_options_test.cljs b/frontend/test/frontend_tests/ui/text_options_test.cljs index 708260fc3c..a0e287f441 100644 --- a/frontend/test/frontend_tests/ui/text_options_test.cljs +++ b/frontend/test/frontend_tests/ui/text_options_test.cljs @@ -18,6 +18,8 @@ [app.main.ui.workspace.sidebar.options.menus.text :as text-menu] [app.main.ui.workspace.sidebar.options.menus.text-cjk-controls :as tcc] [app.main.ui.workspace.sidebar.options.menus.text-language-layout :as tll] + [app.main.ui.workspace.sidebar.options.shapes.text :as text-shape-options] + [app.render-wasm.api :as wasm.api] [app.util.text.content :as tc] [app.util.text.layout :as tl] [app.util.text.writing-mode :as wm] @@ -180,6 +182,15 @@ "workspace.options.text-options.language-group-layout")) "Selected text comes first")) +(t/deftest wasm-editor-left-alive-after-edit-mode-shows-no-text-selection + (let [id (random-uuid)] + (with-redefs [wasm.api/text-editor-get-active-shape-id (constantly id) + wasm.api/text-editor-has-selection? (constantly true)] + (t/is (true? (text-shape-options/wasm-text-range-selected? id id))) + (t/is (false? (text-shape-options/wasm-text-range-selected? id nil)) + "Escape clears the edition before the editor is disposed") + (t/is (false? (text-shape-options/wasm-text-range-selected? id (random-uuid))))))) + (t/deftest language-view-shows-ruby-options-only-for-text-with-ruby (let [group "workspace.options.text-options.language-group-ruby"] (t/is (not (str/includes? (render-language-view "ja" {}) group)))