pub struct CodeBuffer {
pub tab_size: usize,
pub hard_tabs: bool,
pub auto_pair: bool,
/* private fields */
}Expand description
Lines, one selection and an undo history, with code-editing commands.
Fields§
§tab_size: usizeSpaces per indentation level (4 by default).
hard_tabs: boolIndent with '\t' instead of spaces.
auto_pair: boolInsert and skip over closing brackets and quotes.
Implementations§
Source§impl CodeBuffer
impl CodeBuffer
pub fn new(text: &str) -> Self
Sourcepub fn set_text(&mut self, text: &str)
pub fn set_text(&mut self, text: &str)
Replaces the whole text, clears the history and marks it saved (loading a file).
"\r\n" line endings are remembered and restored by CodeBuffer::text.
pub fn line_count(&self) -> usize
pub fn line(&self, ix: usize) -> &str
pub fn lines(&self) -> impl Iterator<Item = &str>
Sourcepub fn longest_line_len(&self) -> usize
pub fn longest_line_len(&self) -> usize
Length in bytes of the longest line.
pub fn selection(&self) -> BufferSelection
pub fn cursor(&self) -> BufferPos
Sourcepub fn text_in(&self, range: Range<BufferPos>) -> String
pub fn text_in(&self, range: Range<BufferPos>) -> String
Text between two positions (joined with '\n').
pub fn selected_text(&self) -> String
Sourcepub fn is_dirty(&self) -> bool
pub fn is_dirty(&self) -> bool
Whether the text differs from the last CodeBuffer::mark_saved (or load).
pub fn mark_saved(&mut self)
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
Sourcepub fn take_edited_from(&mut self) -> Option<usize>
pub fn take_edited_from(&mut self) -> Option<usize>
First line changed since the last call (for highlighter caches), if any.
Sourcepub fn break_undo_group(&mut self)
pub fn break_undo_group(&mut self)
The next edit starts a new undo step even if it continues the current typing.
Sourcepub fn clip(&self, pos: BufferPos) -> BufferPos
pub fn clip(&self, pos: BufferPos) -> BufferPos
The same position kept inside the text and on a character boundary.
Sourcepub fn offset_of(&self, pos: BufferPos) -> usize
pub fn offset_of(&self, pos: BufferPos) -> usize
Byte offset of a position in the '\n'-joined text.
Sourcepub fn pos_of(&self, offset: usize) -> BufferPos
pub fn pos_of(&self, offset: usize) -> BufferPos
Position of a byte offset in the '\n'-joined text.
Sourcepub fn utf16_of(&self, pos: BufferPos) -> usize
pub fn utf16_of(&self, pos: BufferPos) -> usize
UTF-16 offset of a position in the '\n'-joined text.
Sourcepub fn pos_of_utf16(&self, offset: usize) -> BufferPos
pub fn pos_of_utf16(&self, offset: usize) -> BufferPos
Position of a UTF-16 offset in the '\n'-joined text.
Sourcepub fn set_cursor(&mut self, pos: BufferPos, select: bool)
pub fn set_cursor(&mut self, pos: BufferPos, select: bool)
Moves the caret (extending the selection with select). Mouse clicks use this.
pub fn set_selection(&mut self, selection: BufferSelection)
pub fn select_all(&mut self)
Sourcepub fn select_word_at(&mut self, pos: BufferPos)
pub fn select_word_at(&mut self, pos: BufferPos)
Selects the word (or run of spaces or punctuation) at pos (double click).
Sourcepub fn select_line(&mut self, line: usize)
pub fn select_line(&mut self, line: usize)
Selects a whole line, including its line break (triple click).
pub fn move_left(&mut self, select: bool)
pub fn move_right(&mut self, select: bool)
Sourcepub fn move_vertically(&mut self, lines: isize, select: bool)
pub fn move_vertically(&mut self, lines: isize, select: bool)
Moves lines up (negative) or down, keeping the column. Past the first or last line the
caret goes to the start or end of the text.
pub fn move_word_left(&mut self, select: bool)
pub fn move_word_right(&mut self, select: bool)
Sourcepub fn move_home(&mut self, select: bool)
pub fn move_home(&mut self, select: bool)
Smart Home: to the first non-blank character, or to column 0 if already there.
pub fn move_end(&mut self, select: bool)
pub fn move_to_start(&mut self, select: bool)
pub fn move_to_end(&mut self, select: bool)
Sourcepub fn insert(&mut self, text: &str)
pub fn insert(&mut self, text: &str)
Replaces the selection with text as one undo step (paste, completion, drop).
Sourcepub fn replace(&mut self, range: Range<BufferPos>, text: &str)
pub fn replace(&mut self, range: Range<BufferPos>, text: &str)
Replaces a range (an IME composition, a find-and-replace) and puts the caret after it.
Sourcepub fn type_text(&mut self, text: &str)
pub fn type_text(&mut self, text: &str)
Typed text: single characters pair brackets and quotes, skip over a closing one that is already there, and wrap a selection; consecutive typing undoes as one step.
Sourcepub fn newline(&mut self)
pub fn newline(&mut self)
Enter: keeps the line’s indentation, adds a level after an opening bracket and moves the matching closing bracket to its own line.
Sourcepub fn backspace(&mut self)
pub fn backspace(&mut self)
Backspace: deletes the selection, an empty bracket pair, one indentation level inside leading spaces, or the previous character.
Sourcepub fn delete_word_left(&mut self)
pub fn delete_word_left(&mut self)
Deletes to the start of the word (Ctrl+Backspace).
Sourcepub fn delete_word_right(&mut self)
pub fn delete_word_right(&mut self)
Deletes to the end of the word (Ctrl+Delete).
Sourcepub fn indent(&mut self)
pub fn indent(&mut self)
Tab: with a selection over several lines, indents them all; otherwise inserts spaces up
to the next tab stop (or a tab character with CodeBuffer::hard_tabs).
Sourcepub fn outdent(&mut self)
pub fn outdent(&mut self)
Shift+Tab: removes one indentation level from every line the selection touches.
pub fn undo(&mut self) -> bool
pub fn redo(&mut self) -> bool
Trait Implementations§
Source§impl Clone for CodeBuffer
impl Clone for CodeBuffer
Source§impl Debug for CodeBuffer
impl Debug for CodeBuffer
Auto Trait Implementations§
impl Forget for CodeBuffer
impl Freeze for CodeBuffer
impl Move for CodeBuffer
impl RefUnwindSafe for CodeBuffer
impl Send for CodeBuffer
impl Sync for CodeBuffer
impl Unpin for CodeBuffer
impl UnsafeUnpin for CodeBuffer
impl UnwindSafe for CodeBuffer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().