Skip to main content

Module editor

Module editor 

Source
Expand description

Explicitly mutable Normal/Insert buffer state.

EditableBuffer is an opt-in owner of text, mode, cursor, viewport, and byte-limit invariants. It is intentionally separate from read-only crate::motion::apply: an application can reuse every motion without granting editing capability to its documents.

In Mode::Normal, the cursor identifies a Unicode scalar value or column zero on an empty line. In Mode::Insert, it is an insertion point and may equal the line’s byte length. Columns are always UTF-8 byte boundaries; viewport columns are display cells. Every successful move or edit reveals the cursor. Wrong-mode commands, line separators passed as EditorInput::Character, boundary corrections, and input exceeding the configured byte limit return EditOutcome::Ignored rather than panicking.

The caller remains responsible for mapping keys, displaying the active mode, choosing an input limit, and deciding whether a resource is editable. Search prompts with their own confirm/cancel semantics need not use this buffer. The default Insert escape sequence is jj; EditableBuffer inserts a possible prefix immediately, so a lone prefix is never hidden behind a timeout.

§Example

use vim_navigation::editor::{EditOutcome, EditableBuffer, EditorInput};
use vim_navigation::motion::Viewport;

let mut buffer =
    EditableBuffer::with_byte_limit("a", Viewport::new(0, 0, 1, 10, 0), 2);
assert_eq!(buffer.handle(EditorInput::Append), EditOutcome::ModeChanged);
assert_eq!(buffer.handle(EditorInput::Character('界')), EditOutcome::Ignored);
assert_eq!(buffer.handle(EditorInput::Character('b')), EditOutcome::Changed);
assert_eq!(buffer.handle(EditorInput::Escape), EditOutcome::ModeChanged);
assert_eq!(buffer.text(), "ab");

Structs§

EditableBuffer
A text buffer that opts into mutation separately from read-only motion.
InsertEscapeSequence
Configures the character sequence that leaves Insert mode.
InsertEscapeSequenceError
An invalid Insert-mode escape sequence.

Enums§

EditOutcome
The observable effect of one editor input.
EditorInput
Framework-independent input accepted by EditableBuffer.
Mode
The active modal input state.