Skip to main content

EditableBuffer

Struct EditableBuffer 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub const fn insert_escape_sequence(&self) -> &InsertEscapeSequence

Returns the active Insert escape sequence configuration.

Source

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.

Source

pub const fn has_pending_input(&self) -> bool

Reports whether inserted text still matches a prefix of the escape sequence.

Source

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.

Source

pub const fn mode(&self) -> Mode

Returns the active mode.

Source

pub const fn cursor(&self) -> Cursor

Returns the current cursor.

Source

pub const fn viewport(&self) -> &Viewport

Returns the current viewport after any automatic cursor reveal.

Source

pub fn lines(&self) -> &[String]

Returns the logical lines, including a final empty line after a trailing newline.

Source

pub const fn byte_len(&self) -> usize

Returns the content size, including newline separators.

Source

pub fn text(&self) -> String

Allocates and returns the complete buffer content joined with \n.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for EditableBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.