Skip to content

Fix command-line SKK cancel flow so <Esc>/<C-g> abort composition instead of confirming#269

Merged
Shougo merged 2 commits into
masterfrom
copilot/fix-cancel-input-command-line-mode
May 10, 2026
Merged

Fix command-line SKK cancel flow so <Esc>/<C-g> abort composition instead of confirming#269
Shougo merged 2 commits into
masterfrom
copilot/fix-cancel-input-command-line-mode

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 10, 2026

In command-line mode, in-progress SKK composition (e.g. :▽ああ) could not be aborted mid-entry: <Esc> and <C-g> ended up leaving composed text on the command line and triggering invalid command execution. This change adjusts command-line cancellation flow so active composition is discarded before exiting cmdline editing state.

  • Command-line <Esc> now follows cancel semantics during active composition

    • In s:asym_filter(), <Esc> is routed to s:do_cancel() (not s:do_escape()) when mode is c and preedit is non-empty.
    • This avoids the confirm-style path that previously committed composed text.
  • Cancel path now clears preedit state before cmdline escape

    • In s:do_cancel(), cmdline-mode handling now:
      • resets phase to normal
      • clears all preedit buffers
      • emits \<Esc> as a post-rewrite key
    • This ensures cancellation removes ああ / ▽ああ from the cmdline rather than confirming it.
  • Scope control

    • Changes are isolated to command-line cancel behavior; insert-mode and candidate-selection behavior are not otherwise altered.
" before
elseif char ==# "\<Esc>"
  call s:do_escape(a:stash)

" after
elseif char ==# "\<Esc>"
  if mode() ==# 'c' && !preedit.empty()
    call s:do_cancel(a:stash)
  else
    call s:do_escape(a:stash)
  endif
endif
Original prompt

Fix issue #268 in vim-skk/eskk.vim: command-line mode input cannot be cancelled mid-entry.

Issue: #268

Problem summary:
In command-line mode, when the user is in an in-progress SKK input state such as :▽ああ, pressing <ESC> or <C-g> incorrectly confirms the input instead of cancelling it.

Current broken behavior reported in the issue:

  • Pressing <ESC> results in "エディタのコマンドではありません:ああ"
  • Pressing <C-G> results in "エデ��タのコマンドではありません:▽ああ"
  • The user cannot cancel input partway through command-line mode composition.

Expected behavior:

  • In command-line mode, while SKK composition is active, <ESC> and/or <C-g> should cancel the in-progress composition rather than committing text to the command line.
  • The command line should return to a cancelled/cleared state appropriate for Vim command-line editing, instead of leaving composed text behind as a command.

Implementation guidance:

  • Investigate the command-line mode input flow and locate where command-line composition and cancellation keys are handled.
  • Ensure the fix targets command-line mode (: command-line editing), not just candidate-selection (phase:henkan-select) behavior.
  • Preserve existing behavior in insert-mode and candidate-selection flows unless changes are required for consistency.
  • Add or update tests if the repository has an existing test pattern for this behavior.
  • Update documentation only if user-visible key behavior changes or needs clarification.

Acceptance criteria:

  • Reproduce and fix the issue described in コマンドモードで途中で入力がキャンセルできません #268.
  • Verify that command-line mode composition can be cancelled without committing ああ or ▽ああ as a command.
  • Ensure no obvious regression in existing cancellation behavior outside command-line mode.
  • Open a pull request with a clear explanation of the root cause and fix.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: @vim-skk/eskk.vim/pull/266 このプルリクエストをチェックしてください

Assistant: 結論: 大きな設計方針は良く、機能追加として妥当ですが、現時点では 1 点気になる挙動があるので「その確認が取れるまでは approve は保留」が安全です。
特に back-to-henkan の復帰処理が、候補選択前の入力状態を正確に再現できるかを確認したいです。

PR サマリー

  • PR: #266 候補一覧表示時のキャンセル動作をカスタマイズ可能に変更
  • 状態: open / draft
  • マージ可否: mergeable = true, mergeable_state = clean
  • 規模: 3 files changed, +56 / -1
  • コミット数: 6
  • レビュー/コメント:
    • Review: 0
    • Inline comment: 0
    • PR comment: 0
  • CI:
    • commit status は pending
    • ただし status context は 0 件で、実質まだ走っていないか、Checks API 側のみの可能性あり
  • リスク:
    • 理由: UI 入力状態遷移に関わる変更で、正常系は分かりやすい一方、状態復元の境界条件がやや気になるため

この PR の意図は明確です。
候補一覧表示 (phase:henkan-select) 中のキャンセル操作を固定の <C-g> にせず、用途別に切り替えられるようにしています。

追加された選択肢は次の 3 つです。

  • phase:henkan-select:escape
    従来動作
  • phase:henkan-select:back-to-henkan
    変換前の ▽ひらがな 相当へ戻す
  • phase:henkan-select:clear
    入力をクリアする

コア変更

この PR の中心は 2 つです。

  1. マッピング定義の拡張

    • autoload/eskk.vimphase:henkan-select 向けに
      • clear
      • back-to-henkan
        を追加
  2. 候補選択中の入力処理分岐の追加

    • autoload/eskk/dictionary.vim の候補選択プロンプトで、
      • escape
      • back-to-henkan
      • clear
        をそれぞれ別動作に分岐

加えて、doc/eskk.jax に FAQ 形式で設定例が追加されていて、ユーザー向けの導線もあります。
小さな機能追加としてまとまりは良いです。


変更点レビュー

1. マップ定義の追加は自然

autoload/eskk.vim では、既存の phase:henkan-select:* の流れに沿って新しいキー種別を足しており、拡張の仕方として自然です。

+            \   'phase:henkan-select:clear': {},
+            \   'phase:henkan-select:back-to-henkan': {},

また各モードの MODE_LOCAL_KEYS にも追加されているため、設定として露出させる経路は揃っています。
この部分は問題なさそうです。


2. 候補一覧中の escape / clear 分岐は分かりやすい

autoload/eskk/dictionary.vim 側では、従来の固定 <C-g> 判定をやめて、ユーザー設定された lhs を見ています。

+    let back_to_henkan = get(mappings['phase:henkan-select:back-to-henkan'], 'lhs', '')
+    let back_to_henkan = eskk#util#key2char(back_to_henkan)
+    let escape = get(mappings['phase:henkan-select:escape'], 'lhs', '')
+    let escape = eskk#util#key2char(escape)
+    let clear = get(mappings['phase:henkan-select:clear'], 'lhs', '')
+    let clear = eskk#util#key2char(clear)

その後の分岐も意図が明快です。

-        if char ==# "\<C-g>"
+        if char ==# escape
             return a:fallback
+        elseif char ==# back_to_henkan
+            let self._candidates_index = -1
+            call self.preedit.set_henkan_phase(g:eskk#preedit#PHASE_HENKAN)
+            return [self._key, self._okuri]
+        elseif char ==# clear
+            let org_preedit = eskk#get_preedit()
+            call org_preedit.clear_all()
+          ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

Copilot AI changed the title [WIP] Fix command-line mode input cancellation in SKK Fix command-line SKK cancel flow so <Esc>/<C-g> abort composition instead of confirming May 10, 2026
Copilot finished work on behalf of Shougo May 10, 2026 09:52
Copilot AI requested a review from Shougo May 10, 2026 09:52
@Shougo Shougo marked this pull request as ready for review May 10, 2026 09:52
@Shougo Shougo merged commit 00f5088 into master May 10, 2026
2 checks passed
@Shougo Shougo deleted the copilot/fix-cancel-input-command-line-mode branch May 10, 2026 09:53
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.

2 participants