pub struct TextBuffer { /* private fields */ }Expand description
One line of text and a caret, for a text field.
The caret is a character index and moves by grapheme cluster, so an
accent is never split from its letter. The operations are the ones a
shell line has (and Input binds): insert, Backspace,
Delete, Ctrl+U (delete to the start), Ctrl+W (delete a word), and moving
by grapheme or to the ends. checkpoint keeps an
undo point and undo goes back to the last one.
Implementations§
Source§impl TextBuffer
impl TextBuffer
pub fn new() -> TextBuffer
Sourcepub fn with_text(text: impl Into<String>) -> TextBuffer
pub fn with_text(text: impl Into<String>) -> TextBuffer
A buffer holding text, the caret at its end.
pub fn text(&self) -> &str
pub fn is_empty(&self) -> bool
Sourcepub fn set_caret(&mut self, caret: usize)
pub fn set_caret(&mut self, caret: usize)
Put the caret at character caret (clamped to the end), or at the
start of the grapheme caret falls inside.
Sourcepub fn before_caret(&self) -> &str
pub fn before_caret(&self) -> &str
The text before the caret.
Sourcepub fn stops(&self) -> Vec<usize>
pub fn stops(&self) -> Vec<usize>
The character indices where graphemes start, and the end: where the caret may stop.
Sourcepub fn previous_stop(&self) -> usize
pub fn previous_stop(&self) -> usize
The caret one grapheme back.
pub fn home(&mut self)
pub fn end(&mut self)
Sourcepub fn delete_to_start(&mut self)
pub fn delete_to_start(&mut self)
Delete everything before the caret (Ctrl+U).
Sourcepub fn delete_word(&mut self)
pub fn delete_word(&mut self)
Delete the word before the caret, and the spaces after it (Ctrl+W).
Sourcepub fn checkpoint(&mut self)
pub fn checkpoint(&mut self)
Keep the text and caret as an undo point.
Trait Implementations§
Source§impl Clone for TextBuffer
impl Clone for TextBuffer
Source§impl Debug for TextBuffer
impl Debug for TextBuffer
Source§impl Default for TextBuffer
impl Default for TextBuffer
impl Eq for TextBuffer
Source§impl PartialEq for TextBuffer
impl PartialEq for TextBuffer
impl StructuralPartialEq for TextBuffer
Auto Trait Implementations§
impl Freeze for TextBuffer
impl RefUnwindSafe for TextBuffer
impl Send for TextBuffer
impl Sync for TextBuffer
impl Unpin for TextBuffer
impl UnsafeUnpin for TextBuffer
impl UnwindSafe for TextBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.