Skip to main content

CodeBuffer

Struct CodeBuffer 

Source
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: usize

Spaces per indentation level (4 by default).

§hard_tabs: bool

Indent with '\t' instead of spaces.

§auto_pair: bool

Insert and skip over closing brackets and quotes.

Implementations§

Source§

impl CodeBuffer

Source

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

Source

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.

Source

pub fn text(&self) -> String

The whole text, with the line endings it was loaded with.

Source

pub fn line_count(&self) -> usize

Source

pub fn line(&self, ix: usize) -> &str

Source

pub fn lines(&self) -> impl Iterator<Item = &str>

Source

pub fn longest_line_len(&self) -> usize

Length in bytes of the longest line.

Source

pub fn selection(&self) -> BufferSelection

Source

pub fn cursor(&self) -> BufferPos

Source

pub fn text_in(&self, range: Range<BufferPos>) -> String

Text between two positions (joined with '\n').

Source

pub fn selected_text(&self) -> String

Source

pub fn is_dirty(&self) -> bool

Whether the text differs from the last CodeBuffer::mark_saved (or load).

Source

pub fn mark_saved(&mut self)

Source

pub fn can_undo(&self) -> bool

Source

pub fn can_redo(&self) -> bool

Source

pub fn take_edited_from(&mut self) -> Option<usize>

First line changed since the last call (for highlighter caches), if any.

Source

pub fn break_undo_group(&mut self)

The next edit starts a new undo step even if it continues the current typing.

Source

pub fn clip(&self, pos: BufferPos) -> BufferPos

The same position kept inside the text and on a character boundary.

Source

pub fn offset_of(&self, pos: BufferPos) -> usize

Byte offset of a position in the '\n'-joined text.

Source

pub fn pos_of(&self, offset: usize) -> BufferPos

Position of a byte offset in the '\n'-joined text.

Source

pub fn utf16_of(&self, pos: BufferPos) -> usize

UTF-16 offset of a position in the '\n'-joined text.

Source

pub fn pos_of_utf16(&self, offset: usize) -> BufferPos

Position of a UTF-16 offset in the '\n'-joined text.

Source

pub fn set_cursor(&mut self, pos: BufferPos, select: bool)

Moves the caret (extending the selection with select). Mouse clicks use this.

Source

pub fn set_selection(&mut self, selection: BufferSelection)

Source

pub fn select_all(&mut self)

Source

pub fn select_word_at(&mut self, pos: BufferPos)

Selects the word (or run of spaces or punctuation) at pos (double click).

Source

pub fn select_line(&mut self, line: usize)

Selects a whole line, including its line break (triple click).

Source

pub fn move_left(&mut self, select: bool)

Source

pub fn move_right(&mut self, select: bool)

Source

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.

Source

pub fn move_word_left(&mut self, select: bool)

Source

pub fn move_word_right(&mut self, select: bool)

Source

pub fn move_home(&mut self, select: bool)

Smart Home: to the first non-blank character, or to column 0 if already there.

Source

pub fn move_end(&mut self, select: bool)

Source

pub fn move_to_start(&mut self, select: bool)

Source

pub fn move_to_end(&mut self, select: bool)

Source

pub fn insert(&mut self, text: &str)

Replaces the selection with text as one undo step (paste, completion, drop).

Source

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.

Source

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.

Source

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.

Source

pub fn backspace(&mut self)

Backspace: deletes the selection, an empty bracket pair, one indentation level inside leading spaces, or the previous character.

Source

pub fn delete(&mut self)

Delete: deletes the selection or the next character.

Source

pub fn delete_word_left(&mut self)

Deletes to the start of the word (Ctrl+Backspace).

Source

pub fn delete_word_right(&mut self)

Deletes to the end of the word (Ctrl+Delete).

Source

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).

Source

pub fn outdent(&mut self)

Shift+Tab: removes one indentation level from every line the selection touches.

Source

pub fn undo(&mut self) -> bool

Source

pub fn redo(&mut self) -> bool

Trait Implementations§

Source§

impl Clone for CodeBuffer

Source§

fn clone(&self) -> Self

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 CodeBuffer

Source§

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

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

impl Default for CodeBuffer

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

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

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more