Records editing changes as raw key sequences for dot repeat.
A pure functional module — no GenServer. The struct is embedded in
MingaEditor.State and threaded through the editor's key dispatch.
Recording lifecycle
- A change begins (insert mode entry, operator key, single-key edit) →
start_recording/1clears the key buffer and setsrecording: true. - Each key event during the change →
record_key/2appends to the buffer. - The change ends (Escape back to Normal, or operator completes) →
stop_recording/1copies the buffer intolast_change.
During replay (replaying: true), the editor suppresses recording so
the replayed keys don't overwrite the stored change.
Summary
Functions
Buffers a key as a potential part of a future change (e.g., count digits, r prefix).
Cancels the current recording without saving.
Clears pending keys without saving them.
Returns the stored last-change key sequence, or nil if none.
Returns a fresh recorder with no recorded change.
Appends a key to the current recording.
Returns true if currently recording a change.
Replaces the count prefix in a recorded key sequence.
Returns true if currently replaying a change.
Begins recording a new change. Promotes any pending keys into the recording.
Begins recording only if not already recording. Preserves existing keys.
Sets the replaying flag. Recording is suppressed during replay.
Finalizes the current recording into last_change.
Clears the replaying flag.
Types
@type key() :: {non_neg_integer(), non_neg_integer()}
A key event: {codepoint, modifiers}.
Functions
Buffers a key as a potential part of a future change (e.g., count digits, r prefix).
Cancels the current recording without saving.
Discards the key buffer and stops recording. last_change is preserved.
Clears pending keys without saving them.
Returns the stored last-change key sequence, or nil if none.
@spec new() :: t()
Returns a fresh recorder with no recorded change.
Appends a key to the current recording.
No-op if not currently recording.
Returns true if currently recording a change.
@spec replace_count([key()], non_neg_integer() | nil) :: [key()]
Replaces the count prefix in a recorded key sequence.
Strips any leading digit keys (the original count) and prepends
digit keys for the new count. If new_count is nil or 1,
returns the sequence with the original count stripped.
Returns true if currently replaying a change.
Begins recording a new change. Promotes any pending keys into the recording.
Begins recording only if not already recording. Preserves existing keys.
Sets the replaying flag. Recording is suppressed during replay.
Finalizes the current recording into last_change.
The key buffer is moved to last_change and recording stops.
Clears the replaying flag.