🐛 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
This commit is contained in:
alonso.torres 2026-11-24 19:40:54 +01:00
parent 1b7b980f1f
commit 10388a6b77
2 changed files with 23 additions and 2 deletions

View File

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

View File

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