Skip to content

Ctrl+Space の全角スペース入力を config.toml で切替可能にする - #39

Open
asonas wants to merge 8 commits into
togatoga:mainfrom
asonas:feature/configurable-ctrl-space
Open

Ctrl+Space の全角スペース入力を config.toml で切替可能にする#39
asonas wants to merge 8 commits into
togatoga:mainfrom
asonas:feature/configurable-ctrl-space

Conversation

@asonas

@asonas asonas commented Jul 1, 2026

Copy link
Copy Markdown

概要

Ctrl+Space を全角スペース (U+3000) 入力に使うかどうかを config.toml で切り替えられるようにします。

これまで Ctrl+Space は Karukan が消費して全角スペースを入力していました。そのため、ユーザーが OS 側に割り当てた Ctrl+Space ショートカットが発火せず、代わりに全角スペースが入ってしまっていました。本 PR で keys.ctrl_space_fullwidth = false を設定すると、Karukan は Ctrl+Space を消費せず OS へ素通しするようになります。

背景

  • 設定は config.toml の手編集で行います。この Ctrl+Space の挙動もハードコードされており、変更できませんでした。
  • Ctrl+Space は 2 箇所で全角スペースになっていました。未入力時 (Empty, process_key_empty) と入力中 (Composing, process_key_composing) です。いずれも consumed を返すため、フロントがキーを飲み込み OS に届きませんでした。

変更内容

  • karukan-im/config/default.toml: 新セクション [keys]ctrl_space_fullwidth(デフォルト true)を追加します。
  • karukan-im/src/config/settings.rs: KeysSettings 構造体と Settings.keys フィールドを追加します。ユーザー設定に [keys] が無い場合も、既存の merge_toml でデフォルトが埋まります。
  • karukan-im/src/core/engine/types.rs: EngineConfigctrl_space_fullwidth: bool を追加し、from_settings(設定から反映)と Defaulttrue)に反映します。
  • karukan-im/src/core/engine/input.rs: Empty / Composing 両状態の Ctrl+Space 分岐に flag チェックを追加します。false のときは not_consumed を返して OS へ素通しします。Composing 側は変換トリガーへのフォールスルーを防ぐため、明示的に not_consumed を返します。

not_consumed を返せばフロント(macOS Swift / Linux fcitx5)が自動で OS へキーを渡すため、フロントエンド (Swift / C++) は無変更で macOS / Linux 両対応となります。

挙動

ctrl_space_fullwidth Empty / Composing での Ctrl+Space
true(デフォルト・従来通り) 全角スペース (U+3000) を入力します
false OS へ素通しします(ウインドウ切替などのショートカットが効きます)

デフォルトは true のため、既存ユーザーの挙動は変わりません(後方互換です)。

スコープ外(意図的)

候補ウィンドウ表示中(Conversion 状態)の Ctrl+Space は、ctrl_space_fullwidth の値によらず従来通り「次の候補へ」として消費されます。候補表示中のウインドウ切替は稀であり、既存の bare-Space の候補送り挙動と揃える意図で、今回の設定対象外としています(設計 spec に明記しています)。

テスト

  • karukan-im の全テスト 227 件が pass し、cargo clippy / cargo fmt --check もクリーンです。
  • 追加したテストは次のとおりです。
    • 設定読み込み: [keys] のデフォルト値、false オーバーライド、未指定セクションのデフォルト維持
    • 設定伝搬: EngineConfig のデフォルト truefrom_settings マッピング
    • キー挙動: Empty × 2(有効/無効)、Composing × 2(有効/無効。無効側は変換トリガーへ誤消費しないことを検証)

asonas added 8 commits August 8, 2026 16:48
Defines the design for making Ctrl+Space behavior configurable via
config.toml. Currently hardcoded to intercept Ctrl+Space for
full-width space input, preventing OS shortcuts from triggering.
This spec allows users to disable the interception while maintaining
backward compatibility with existing behavior as the default.
This plan outlines a TDD-driven implementation to make Ctrl+Space behavior
configurable via config.toml. Users can choose whether Ctrl+Space inputs a
full-width space (current behavior, kept as default) or passes through to the
OS for window-switching and other shortcuts. The implementation adds a single
boolean flag through the existing settings propagation path: config.toml →
Settings → EngineConfig → engine key handling. Tasks cover settings struct,
config mapping, and key processing in Empty and Composing states, with
comprehensive test cases for both enabled and disabled modes.
Introduce a new [keys] configuration section that allows users to
control whether Ctrl+Space inputs a full-width space (U+3000) or
passes through to the OS for system shortcuts like window switching.

The new ctrl_space_fullwidth setting defaults to true (current
behavior) but can be set to false in config.toml to restore
OS-level Ctrl+Space handling on macOS and Linux. This gives users
full control over key interception without requiring code changes
or rebuilds.
Add a new ctrl_space_fullwidth configuration to EngineConfig that
controls whether Ctrl+Space inputs a full-width space (U+3000). When
false, Ctrl+Space passes through to the OS without being consumed by
the engine.

The setting defaults to true and can be customized via the Settings
structure. Include tests to verify the default value and that the
setting correctly maps from user configuration.
When ctrl_space_fullwidth is false, Ctrl+Space key presses are
not consumed and pass through to the OS, allowing window-switching
shortcuts and other keybindings to function normally.

Add tests to verify behavior in both enabled and disabled states:
- ctrl_space_inputs_fullwidth_space_in_empty_when_enabled
- ctrl_space_passes_through_in_empty_when_disabled
Make the Ctrl+Space full-width space insertion configurable via the
`ctrl_space_fullwidth` setting. When disabled, Ctrl+Space passes through
to the OS instead of being consumed by the engine.

This prevents the fall-through bug where Ctrl+Space would trigger
conversion mode if the bare-Space handler were to execute. An explicit
return statement ensures correct control flow regardless of the config
setting.

Add tests to verify both enabled and disabled behavior while composing.
Clarify that the ctrl_space_fullwidth configuration
only applies to Empty and Composing states. In
Conversion state, Ctrl+Space always navigates to the
next candidate regardless of the configuration,
maintaining consistency with existing Space behavior
and recognizing that window switching while viewing
candidates is rare.
@asonas
asonas force-pushed the feature/configurable-ctrl-space branch from 32dd3e4 to 727c658 Compare August 8, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant