Skip to main content

TextBuffer

Struct TextBuffer 

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

A TextDocument held in memory as a line per String.

What a form gets, and what an application with an ordinary amount of text wants. Undo is a journal of the edits, so it costs what was typed rather than a copy of the text per keystroke; consecutive typing on one line is one entry.

Implementations§

Source§

impl TextBuffer

Source

pub fn new() -> Self

An empty buffer: one empty line.

Source

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

A buffer holding text.

Source

pub fn text(&self) -> String

The whole text, lines joined by \n.

Source

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

The lines.

Trait Implementations§

Source§

impl Clone for TextBuffer

Source§

fn clone(&self) -> TextBuffer

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 TextBuffer

Source§

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

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

impl Default for TextBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TextDocument for TextBuffer

Source§

fn line_count(&mut self) -> Option<usize>

How many lines there are, or None while that is still being counted. Read more
Source§

fn known_lines(&mut self) -> usize

Lines the document can hand over now. Equal to line_count once it is known, and growing until then.
Source§

fn line(&mut self, n: usize) -> Option<Cow<'_, str>>

Line n without its newline, or None if it is not (yet) known.
Source§

fn insert(&mut self, at: Pos, text: &str)

Inserts text, which may hold newlines, at at.
Source§

fn delete(&mut self, from: Pos, to: Pos)

Deletes [from, to). from <= to; a range across lines joins them.
Source§

fn undo(&mut self) -> bool

Takes back the last edit. false if there was none.
Source§

fn redo(&mut self) -> bool

Redoes the last edit undone. false if there was none.
Source§

fn spans(&mut self, n: usize, out: &mut Vec<Span>)

The coloured runs of line n, appended to out in ascending order without overlaps. Text between runs is drawn in the theme’s content colour. The default highlights nothing.
Source§

fn highlights(&mut self, n: usize, line: &str, out: &mut Vec<Range<usize>>)

Byte ranges of line n to mark behind the text — every match of a search, say — appended to out in ascending order without overlaps. line is the line’s text as the widget already has it, so marking costs no second read. A range out of order, past the end or not on a character boundary is skipped; the selection is drawn over the marks. The default marks nothing.

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> AsAny for T
where T: Any,

Source§

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

Borrows as dyn Any.
Source§

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

Mutably borrows as dyn Any.
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> 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> 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 = !

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.