Skip to main content

EditBuffer

Struct EditBuffer 

Source
pub struct EditBuffer { /* private fields */ }
Expand description

Shared Pi-style flat text editing model used by the widget and chat editors.

Implementations§

Source§

impl EditBuffer

Source

pub fn new(text: &str) -> Self

Creates a buffer with the cursor at the end of sanitized text.

Source

pub const fn set_xml(&mut self, xml: bool)

Enables </ close-tag completion (on by default).

Source

pub fn text(&self) -> &str

Returns the visible marker text.

Source

pub const fn cursor(&self) -> usize

Returns the UTF-8 byte cursor.

Source

pub fn line_count(&self) -> usize

Returns the number of logical newline-delimited lines.

Source

pub fn cursor_line(&self) -> usize

Returns the zero-based logical cursor line.

Source

pub fn cursor_column(&self) -> u16

Returns the cursor’s cell column within its logical line.

Source

pub fn logical_lines( &self, ) -> impl DoubleEndedIterator<Item = &str> + Clone + FusedIterator + '_

Iterates logical lines without allocating.

Source

pub fn replace_external(&mut self, text: &str, cursor_at_start: bool)

Replaces text without creating an undo entry, for history browsing.

Source

pub fn set_cursor_line_column(&mut self, line: usize, column: u16)

Places the cursor on a logical line and cell column.

Source

pub fn set_cursor_visual_row( &mut self, row: usize, column: u16, width_limit: u16, )

Places the cursor on a visual row and cell column.

Source

pub fn replace_range(&mut self, range: Range<usize>, replacement: &str)

Replaces a byte range as one undoable edit. A non-empty range that touches an atomic marker widens to the whole marker, so partial replacements can never tear a unit apart.

Source

pub fn insert_text(&mut self, text: &str) -> BufferOutcome

Inserts sanitized text at the cursor.

Text is inserted verbatim; hosts that collapse large pastes into compact chips stage them through EditBuffer::insert_reference.

Source

pub fn expanded_text(&self) -> String

Returns text with every atomic reference expanded to its payload.

Source

pub fn insert_reference(&mut self, marker: &str, payload: &str) -> BufferOutcome

Inserts an atomic reference at the cursor: marker is displayed, navigated, and deleted as one unit, and expands to payload in the submitted text. marker must be a single line.

The unit is tracked by position, not by content: typed text that happens to equal marker stays ordinary text.

Source

pub fn atom_ranges(&self) -> SmallVec<(usize, usize), 4>

Byte ranges of atomic markers present in the text, ascending. Slice EditBuffer::text with a range to recover the marker.

Source

pub fn clear_after_submit(&mut self) -> String

Returns expanded text and resets the buffer after submission.

Source

pub fn handle( &mut self, key: Key, width: u16, page_rows: usize, ) -> BufferOutcome

Applies a decoded editor key at the given layout width.

Source

pub fn rows( &self, width_limit: u16, max_rows: usize, ) -> SmallVec<VisualRow<'_>, 8>

Returns the visible visual rows.

Keyboard editing keeps the cursor in view. A manual viewport scroll remains detached until the next editing command.

Source

pub fn scroll_rows(&self, delta: i32, width_limit: u16, max_rows: usize) -> bool

Moves the visible row window without moving the cursor.

Returns whether the clamped viewport offset changed.

Source

pub fn visual_height(&self, width: u16, max_rows: usize) -> usize

Returns the clipped visual row count.

Source

pub fn at_visual_start(&self) -> bool

Reports whether the cursor is at the document’s visual start.

Source

pub fn at_visual_end(&self) -> bool

Reports whether the cursor is at the document’s visual end.

Trait Implementations§

Source§

impl Clone for EditBuffer

Source§

fn clone(&self) -> EditBuffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EditBuffer

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for EditBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.