Skip to content

打ち続けて確定した変換も確定アンドゥで取り消せるようにする - #258

Merged
Shougo merged 1 commit into
vim-skk:mainfrom
delphinus:fix/kakutei-undo-implicit-kakutei
Sep 17, 2026
Merged

Shougo merged 1 commit into
vim-skk:mainfrom
delphinus:fix/kakutei-undo-implicit-kakutei

Conversation

@delphinus

Copy link
Copy Markdown
Contributor

#257 で入れた確定アンドゥが、<C-j> などの確定キーを押さずに打ち続けて確定した場合に利用出来なくなっていました。

再現

  1. <C-z> に kakuteiUndo を割り当てます。
  2. KiMe と打って ▼決め を出し、確定キーを押さずにそのまま ru と打ちます。「決め」が確定して「決める」になります。
  3. <C-h> で「る」を消すと確定した文字列がカーソルの直前に戻りますが、ここで <C-z> を押しても何も起きません。
    • ru の前に <C-j> を挟んで確定した場合は「▼決め」に戻ります。

補完でも同じことが起きます。候補を選んだまま打ち続けて確定すると、ポップアップを閉じたキーの pre-edit が確定した文字列の後ろに並ぶため、同じように取り消せませんでした (ポップアップから <C-y> などで確定した場合は取り消せます)。

原因

確定した文字列がバッファのどの位置に入ったかは次のキー処理まで分からないので、カーソル前の行がその文字列で終わっているかどうかで判断していました。打ち続けての確定では、確定させたキー自身の入力が同じキー処理の中で確定した文字列の後ろに並びます。その場合想定と違う文字列になるため、記録を捨てていました。

直し方

確定を記録した後に同じキー処理が書いた分を覚えておき、それと現在の preEdit を取り除いてから、確定した文字列を探すようにしました。これが想定と一致していれば記録として残します。

実バッファ (Neovim) の統合テストを 1 本足しました。ドキュメントに書いた「続けて入力した文字を消してカーソルが戻った場合も動作します」のとおりになるだけなので、doc/ は変更していません。

#257 で相談していた件とは別に入れたい修正です。

🤖 Generated with Claude Code

kakuteiUndo could only take back a kakutei done by a kakutei key. A candidate
is confirmed by typing on as well, and the same key handling then writes the
input of that key behind the confirmed string. The pending kakutei is
resolved at the next key handling by looking for the confirmed string at the
end of the line before the cursor, which no longer matched, so the record was
dropped and there was nothing left to take back. A completion confirmed by
typing on has the same shape: the key which closes the popup is handled
before CompleteDone reports the kakutei, hence the pre-edit of that key sits
behind the confirmed string as well.

Remember what the rest of the key handling writes behind a recorded kakutei,
and strip it, along with the pre-edit which is in the buffer, before looking
for the confirmed string. Nothing is stripped when the line does not end with
it, which is what a completion confirmed from the popup looks like: the
engine has rewritten the buffer and the pre-edit skkeleton remembers is a
stale one. That path resolves as it did before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Shougo

Shougo commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

マージします

@Shougo
Shougo merged commit ba02dd5 into vim-skk:main Sep 17, 2026
2 checks passed
@delphinus
delphinus deleted the fix/kakutei-undo-implicit-kakutei branch September 19, 2026 06:06
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