Skip to main content

Module keymap_replace

Module keymap_replace 

Source
Expand description

Replace-mode binding registration + drift-test helpers.

Audit slice 8.d. The smallest mode in input.rs’s hand-rolled match table – only four binding shapes:

ChordAction
<Esc>EnterMode(Normal)
<BS>ReplaceUndoLast
<CR>Insert("\n")
any bare printableOverwriteChar(c) (wildcard)

Plus the legacy guard: any modifier-bearing key (<C-x>, <M-x>, …) returns Action::None. The trie’s “wildcard only matches bare printable chars” rule (audit slice 8.b) preserves this for free.

§What this slice ships

  • register_replace_bindings – the four entries the App’s startup wires into the KeymapHandle under KeymapLayer::Builtin + BindingMode::Replace.
  • dispatch_replace – the registry-driven dispatcher. KeyEvent → KeyChord → handle.lookup → Action. input::translate calls this for ModalState::Replace; the App constructs a populated KeymapHandle in [crate::app::App::new] and the runtime threads it through crate::input::TranslateContext every frame.
  • Drift test in this module’s test block – exhaustive over the keys Replace mode cares about, asserting that dispatch_replace(handle, ev) == the legacy translate_replace’s reference body for every input. The reference body is kept private to the test module (a literal copy of the pre-migration match table) so a future refactor can’t drift the dispatcher away from the documented Replace-mode semantics. Slice 8.i retires the reference body once every binding routes through a real CommandInvocation.

§Migration template

Subsequent slices (8.e Visual, 8.f Insert, 8.g Normal) follow the same shape: register_<mode>_bindings, dispatch_<mode>, and a per-mode drift test against the legacy translate_<mode> function. Keep the legacy function private to its test module for the duration of the migration; drop it in slice 8.i when the merged catalog covers the whole keystroke surface.

Functions§

dispatch_replace
Dispatch a key event through the keymap registry.
register_replace_bindings
Register the four Replace-mode bindings into the supplied handle’s Builtin layer. Called by the App at startup (slice 8.h wires the call site once the App-level keymap boot finalises).