Skip to content

fix: let fed <BS> replace the pre-edit through the guard - #2

Merged
kjuq merged 1 commit into
kjuq:masterfrom
atusy:fix/guard-fed-backspace
Oct 19, 2026
Merged

kjuq merged 1 commit into
kjuq:masterfrom
atusy:fix/guard-fed-backspace

Conversation

@atusy

@atusy atusy commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Completion UIs replace the typed input with a candidate by feeding <BS> (noremap) and then the candidate text:

  • pum.vim does this when cancelling a selection (s:insert_line_feedkeys)
  • laser.nvim does it on every select, confirm and cancel

During pre-edit, the guard treats these fed <BS> as unmapped physical keys and discards them. The candidate is then appended after the pre-edit instead of replacing it:

Kanji → select 漢字 → ▽かんじ漢字   (expected: 漢字)

Cancelling a selection also cannot restore the reading.

Change

The guard now passes <BS> through when vim.on_key reports no typed key (typed == ""). The fix is scoped narrowly:

  • Physical <BS> reaching the guard unmapped is still discarded.
  • <BS> replayed by a macro is still discarded. vim.on_key reports macro replay as untyped too, so reg_executing() is checked as well.
  • Other special keys stay discarded even when fed. Replacing input only needs <BS>, and cursor motions such as <Left> are what leave the ▽ marker behind.

The replacement desynchronizes the pre-edit tracking. That is recovered by the existing prevInput mismatch reset, just as it is for insertOnSelect.

Tests

In tests/integration_spec.lua:

  • fed <BS> from a completion UI replaces the pre-edit: fails on master with ▽かんじ漢字 and passes with this change.
  • <BS> reaching the guard unmapped is discarded unless fed: physical and macro-replayed <BS> are still discarded.

env -u NVIM_LISTEN_ADDRESS nvim --clean --headless -l tests/run.lua: all tests passed on the rebased branch, including the macro regression tests.

Rebased onto master at b1e8d46. The insert-mode :lmap change does not remove the need to allow completion UIs’ fed <BS> through the guard.

This fix is independent of #1.

🤖 Generated with Claude Code

@atusy
atusy force-pushed the fix/guard-fed-backspace branch from 6001a49 to c2d2f28 Compare September 24, 2026 15:59
atusy added a commit to atusy/dotfiles that referenced this pull request Sep 25, 2026
laser types a selected candidate as <BS> and then the word, but
skkelua's guard discards any unmapped <BS> during pre-edit as a physical
key. Selecting a candidate for ▽かんじ therefore produced ▽かんじ漢字,
and cancelling could not restore the reading.

Wrap the guard so that it passes <BS> that was fed rather than typed,
while still guarding macro replay and every other key. This is a
stopgap until kjuq/skkelua.nvim#2 fixes the guard itself. It is not
done by mapping <BS>, because laser feeds its keys noremap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Completion UIs replace the typed input with a candidate by feeding <BS>
noremap and then the candidate: pum.vim does so when cancelling, and
laser.nvim whenever it selects, confirms or cancels. The guard took
these <BS> for unmapped physical keys and discarded them during
pre-edit, so the candidate was appended after the pre-edit instead
(▽かんじ漢字) and cancelling could not restore the reading.

Pass <BS> through when vim.on_key reports no typed key. Physical <BS>
reaching the guard unmapped is still discarded, and so is <BS> replayed
by a macro, which vim.on_key also reports as untyped. Other special
keys stay discarded even when fed, since only <BS> is needed to replace
the input and cursor motions are what leave the ▽ marker behind. The
pre-edit tracking that the replacement desynchronizes is recovered by
the prevInput mismatch reset, as with insertOnSelect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@atusy
atusy force-pushed the fix/guard-fed-backspace branch from c2d2f28 to 931b0d7 Compare October 1, 2026 13:49
@kjuq
kjuq merged commit f2a9228 into kjuq:master Oct 19, 2026
2 checks passed
atusy added a commit to atusy/dotfiles that referenced this pull request Oct 21, 2026
skkelua's guard now passes fed <BS> through by itself (kjuq/skkelua.nvim#2),
so patching its private _on_key is no longer needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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