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