From dd701f06baa6d617c90906b754d08696978a6f50 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 16 Jul 2026 12:44:41 +0200 Subject: [PATCH] remove explicit activation flag --- .../options/menus/text_japanese_layout.cljs | 126 +++++------------- .../options/menus/text_japanese_layout.scss | 6 - .../frontend_tests/ui/text_options_test.cljs | 23 +--- frontend/translations/en.po | 4 - frontend/translations/jpn_JP.po | 4 - 5 files changed, 33 insertions(+), 130 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.cljs index fe3779156f..e701d0de1a 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.cljs @@ -61,16 +61,6 @@ :disabled true :dimmed true}))) -(defn japanese-layout-enabled? - "Japanese layout is opt-in. An explicit supported writing mode is the - persisted marker; absent, mixed, or reset values remain ordinary text." - [values] - (let [writing-mode (:writing-mode values)] - (cond - (= writing-mode :multiple) nil - (#{"horizontal-tb" "vertical-rl"} writing-mode) true - :else false))) - (defn japanese-layout-config-enabled? "Japanese layout controls are available when enabled for the current file or globally in the user's profile." @@ -78,21 +68,6 @@ (or (ctf/japanese-layout-enabled? file-data) (true? (get-in profile [:props :japanese-layout-all-files])))) -(defn japanese-layout-toggle-attrs - "Attrs emitted by the Japanese layout switch. A nil writing mode removes the - persisted paragraph attribute, restoring the normal horizontal default." - [enabled?] - {:writing-mode (when enabled? "horizontal-tb")}) - -(defn reconcile-japanese-layout-state - "Keep the current opt-in state when a same-selection style snapshot omits - writing-mode. A new selection resets from its persisted paragraph value." - [current values selection-changed?] - (cond - selection-changed? (japanese-layout-enabled? values) - (#{"horizontal-tb" "vertical-rl"} (:writing-mode values)) true - :else current)) - (defn vertical-japanese-layout? "True when the Japanese layout controls are editing vertical text." [values] @@ -125,27 +100,6 @@ ;; Sub-components ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(mf/defc japanese-layout-toggle* - [{:keys [values enabled on-change on-toggle on-blur]}] - (let [handle-change - (mf/use-fn - (mf/deps on-change on-toggle on-blur) - (fn [checked?] - (on-toggle checked?) - (on-change (japanese-layout-toggle-attrs checked?)) - (when (some? on-blur) (on-blur))))] - - ;; Repair the invalid reset sentinel emitted by the previous implementation - ;; so an already-open document can recover without a reload or manual edit. - (mf/with-effect [(:writing-mode values) on-change] - (when (= "" (:writing-mode values)) - (on-change {:writing-mode nil}))) - - [:div {:class (stl/css :japanese-layout-toggle)} - [:> switch* {:default-checked enabled - :label (tr "workspace.options.text-options.japanese-layout-enable-for-text") - :on-change handle-change}]])) - (mf/defc writing-mode-options* [{:keys [values on-change on-blur]}] (let [writing-mode (radio-selected (:writing-mode values) "horizontal-tb") @@ -559,56 +513,36 @@ :on-change handle-change}]])) (mf/defc japanese-layout-options* - [{:keys [ids values ruby-values text-selection-active + [{:keys [values ruby-values text-selection-active on-change on-ruby-presentation-change on-blur]}] - (let [selection-key (hash ids) - previous-selection-key-ref (mf/use-ref selection-key) - active* (mf/use-state #(japanese-layout-enabled? values)) - active? (deref active*) - vertical? (vertical-japanese-layout? values) - toggle (mf/use-fn #(reset! active* %)) - common-props (mf/props - {:values values - :on-change on-change - :on-blur on-blur}) - ruby-presentation-props (mf/props - {:values ruby-values - :on-change on-ruby-presentation-change - :on-blur on-blur}) - toggle-props (mf/spread-props - common-props - {:enabled active? - :on-toggle toggle})] - - (mf/with-effect [selection-key (:writing-mode values)] - (let [selection-changed? - (not= selection-key (mf/ref-val previous-selection-key-ref))] - (reset! active* - (reconcile-japanese-layout-state active? - values - selection-changed?)) - (mf/set-ref-val! previous-selection-key-ref selection-key))) + (let [vertical? (vertical-japanese-layout? values) + common-props (mf/props + {:values values + :on-change on-change + :on-blur on-blur}) + ruby-presentation-props (mf/props + {:values ruby-values + :on-change on-ruby-presentation-change + :on-blur on-blur})] [:div {:class (stl/css :japanese-layout-options)} - [:> japanese-layout-toggle* toggle-props] - (when ^boolean active? - [:div {:class (stl/css :japanese-layout-controls)} - [:div {:class (stl/css :japanese-icon-options)} - [:> writing-mode-options* common-props] - (when ^boolean vertical? - [:* - [:> text-orientation-options* common-props] - [:> text-combine-upright-options* - (mf/spread-props common-props - {:text-selection-active text-selection-active})]]) - (when ^boolean text-selection-active - [:> warichu-options* common-props])] - (when ^boolean vertical? - [:> text-combine-upright-count-options* common-props]) - [:> font-features-options* common-props] - (when ^boolean text-selection-active - [:> text-emphasis-options* common-props]) - [:> annotation-clearance-options* common-props] - (if text-selection-active - [:> ruby-advanced-options* common-props] - [:> ruby-presentation-options* ruby-presentation-props])])])) + [:div {:class (stl/css :japanese-layout-controls)} + [:div {:class (stl/css :japanese-icon-options)} + [:> writing-mode-options* common-props] + (when ^boolean vertical? + [:* + [:> text-orientation-options* common-props] + [:> text-combine-upright-options* + (mf/spread-props common-props + {:text-selection-active text-selection-active})]]) + (when ^boolean text-selection-active + [:> warichu-options* common-props])] + (when ^boolean vertical? + [:> text-combine-upright-count-options* common-props]) + [:> font-features-options* common-props] + (when ^boolean text-selection-active + [:> text-emphasis-options* common-props]) + [:> annotation-clearance-options* common-props] + (if text-selection-active + [:> ruby-advanced-options* common-props] + [:> ruby-presentation-options* ruby-presentation-props])]])) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.scss b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.scss index 1211c32e68..e9ddb3c921 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.scss +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.scss @@ -58,12 +58,6 @@ padding-block: var(--sp-xs); } -.japanese-layout-toggle { - display: flex; - align-items: center; - min-block-size: $sz-32; -} - .ruby-hidden-option { min-block-size: $sz-32; } diff --git a/frontend/test/frontend_tests/ui/text_options_test.cljs b/frontend/test/frontend_tests/ui/text_options_test.cljs index 4cfb230e6a..37a4267bfe 100644 --- a/frontend/test/frontend_tests/ui/text_options_test.cljs +++ b/frontend/test/frontend_tests/ui/text_options_test.cljs @@ -229,32 +229,15 @@ (t/is (= {:ruby-hidden nil} (content-styles/styles->attrs {"--ruby-hidden" ""})))) -(t/deftest japanese-layout-is-explicitly-enabled-by-writing-mode - (t/is (false? (tjl/japanese-layout-enabled? {}))) - (t/is (false? (tjl/japanese-layout-enabled? {:writing-mode nil}))) - (t/is (true? (tjl/japanese-layout-enabled? {:writing-mode "horizontal-tb"}))) - (t/is (true? (tjl/japanese-layout-enabled? {:writing-mode "vertical-rl"}))) - (t/is (nil? (tjl/japanese-layout-enabled? {:writing-mode :multiple})))) - -(t/deftest japanese-layout-toggle-emits-a-persisted-writing-mode - (t/is (= {:writing-mode "horizontal-tb"} - (tjl/japanese-layout-toggle-attrs true))) - (t/is (= {:writing-mode nil} - (tjl/japanese-layout-toggle-attrs false)))) - -(t/deftest japanese-layout-state-survives-transient-selection-styles - (t/is (true? (tjl/reconcile-japanese-layout-state true {} false))) - (t/is (true? (tjl/reconcile-japanese-layout-state false - {:writing-mode "vertical-rl"} - false))) - (t/is (false? (tjl/reconcile-japanese-layout-state true {} true)))) - (t/deftest japanese-controls-distinguish-horizontal-and-vertical-modes + (t/is (false? (tjl/vertical-japanese-layout? {}))) (t/is (false? (tjl/vertical-japanese-layout? {:writing-mode "horizontal-tb"}))) (t/is (true? (tjl/vertical-japanese-layout? {:writing-mode "vertical-rl"}))) (t/is (= "palt" (tjl/proportional-metrics-feature "horizontal-tb"))) + (t/is (= "palt" + (tjl/proportional-metrics-feature nil))) (t/is (= "vpal" (tjl/proportional-metrics-feature "vertical-rl")))) diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 463df36f3f..89576c0d3c 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -8542,10 +8542,6 @@ msgstr "Normal" msgid "workspace.options.text-options.japanese-layout" msgstr "Japanese text layout" -#: src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.cljs -msgid "workspace.options.text-options.japanese-layout-enable-for-text" -msgstr "Enable for this text" - #: src/app/main/ui/workspace/sidebar/options/menus/text.cljs msgid "workspace.options.text-options.text-combine-upright-all" msgstr "Tate-chu-yoko" diff --git a/frontend/translations/jpn_JP.po b/frontend/translations/jpn_JP.po index c75ffc9b9c..c4b3c5e743 100644 --- a/frontend/translations/jpn_JP.po +++ b/frontend/translations/jpn_JP.po @@ -992,10 +992,6 @@ msgstr "通常" msgid "workspace.options.text-options.japanese-layout" msgstr "日本語組版" -#: src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.cljs -msgid "workspace.options.text-options.japanese-layout-enable-for-text" -msgstr "このテキストで有効にする" - #: src/app/main/ui/workspace/sidebar/options/menus/text.cljs msgid "workspace.options.text-options.text-combine-upright-all" msgstr "縦中横"