pub struct EditableBuffer { /* private fields */ }Expand description
A text buffer that opts into mutation separately from read-only motion.
The buffer always contains at least one line. Cursor columns remain UTF-8
boundaries. In Normal mode the cursor is on a character (or column zero for
an empty line); in Insert mode it may also be at the byte length of the line.
The safe public operations clamp external coordinates and report
unsupported or boundary input as EditOutcome::Ignored; they do not panic
for caller-controlled positions or input.
Implementations§
Source§impl EditableBuffer
impl EditableBuffer
Sourcepub fn new(text: &str, viewport: Viewport) -> Self
pub fn new(text: &str, viewport: Viewport) -> Self
Creates an editable buffer without a library-enforced insertion limit.
Applications accepting untrusted or long-lived input should normally
choose Self::with_byte_limit instead.
Sourcepub fn with_byte_limit(
text: &str,
viewport: Viewport,
byte_limit: usize,
) -> Self
pub fn with_byte_limit( text: &str, viewport: Viewport, byte_limit: usize, ) -> Self
Creates an editable buffer whose future content cannot exceed byte_limit bytes.
Existing input is retained even when it already exceeds the limit; the
limit only prevents additional characters or newlines until corrections
bring the content below it. The size is UTF-8 content bytes plus one byte
for each logical \n separator. Initial text is preserved verbatim:
only \n splits lines, and \r remains content. Callers wanting CRLF
normalization should perform it before construction.
Sourcepub fn with_insert_escape_sequence(self, sequence: InsertEscapeSequence) -> Self
pub fn with_insert_escape_sequence(self, sequence: InsertEscapeSequence) -> Self
Replaces the default jj Insert escape sequence for this buffer.
This builder is intended for construction-time configuration. Use
Self::set_insert_escape_sequence to replace it later.
Sourcepub const fn insert_escape_sequence(&self) -> &InsertEscapeSequence
pub const fn insert_escape_sequence(&self) -> &InsertEscapeSequence
Returns the active Insert escape sequence configuration.
Sourcepub fn set_insert_escape_sequence(&mut self, sequence: InsertEscapeSequence)
pub fn set_insert_escape_sequence(&mut self, sequence: InsertEscapeSequence)
Replaces the Insert escape sequence without discarding a typed prefix.
A pending prefix has already been inserted literally, so changing the configuration commits it simply by forgetting its escape-candidate status.
Sourcepub const fn has_pending_input(&self) -> bool
pub const fn has_pending_input(&self) -> bool
Reports whether inserted text still matches a prefix of the escape sequence.
Sourcepub fn flush_pending_input(&mut self) -> bool
pub fn flush_pending_input(&mut self) -> bool
Commits a possible escape prefix as literal input.
The prefix is already present in the text, so this operation only clears recognition state and returns whether any state was cleared. Call it before an application changes focus or associates this buffer with a different input target. Dropping or abandoning the resolver without a flush still cannot lose the typed characters.
Sourcepub const fn viewport(&self) -> &Viewport
pub const fn viewport(&self) -> &Viewport
Returns the current viewport after any automatic cursor reveal.
Sourcepub fn resize(&mut self, height: usize, width: usize, gutter: usize)
pub fn resize(&mut self, height: usize, width: usize, gutter: usize)
Updates the pane dimensions and reveals the cursor in the resized pane.
Height is measured in logical lines; width and gutter are display cells.
Zero height or width is normalized to one, as in Viewport::new. Text,
mode, cursor, desired column, and a pending Insert escape sequence are
preserved. Only viewport geometry and the scroll position can change.
Sourcepub fn lines(&self) -> &[String]
pub fn lines(&self) -> &[String]
Returns the logical lines, including a final empty line after a trailing newline.
Sourcepub fn set_cursor(&mut self, cursor: Cursor)
pub fn set_cursor(&mut self, cursor: Cursor)
Selects a cursor, clamps it according to the active mode, and reveals it.
A line beyond the buffer selects the final line. A byte inside a UTF-8 scalar rounds backward to that scalar’s start. Subsequent vertical motions derive their desired column from this selection.
Sourcepub fn handle(&mut self, input: EditorInput) -> EditOutcome
pub fn handle(&mut self, input: EditorInput) -> EditOutcome
Applies one framework-independent input according to the active mode.
EditOutcome::Changed takes precedence when an input also enters
Insert mode or moves the cursor, as o and O do. An ignored input
leaves content, cursor, viewport, and mode unchanged. It may still
advance escape-sequence recognition when the byte limit prevents a
possible prefix from being inserted.