TextCore

Struct TextCore 

Source
pub struct TextCore<Store> { /* private fields */ }
Expand description

Core for text editing.

Implementations§

Source§

impl<Store: TextStore + Default> TextCore<Store>

Source

pub fn new( undo: Option<Box<dyn UndoBuffer>>, clip: Option<Box<dyn Clipboard>>, ) -> Self

Source

pub fn set_newline(&mut self, br: String)

Sets the line ending to be used for insert. There is no auto-detection or conversion done for set_value().

Caution: If this doesn’t match the line ending used in the value, you will get a value with mixed line endings.

Defaults to the system line-ending.

Source

pub fn newline(&self) -> &str

Line ending used for insert.

Source

pub fn set_tab_width(&mut self, tabs: u16)

Set the tab-width. Default is 8.

Source

pub fn tab_width(&self) -> u16

Tab-width

Source

pub fn set_expand_tabs(&mut self, expand: bool)

Expand tabs to spaces. Only for new inputs.

Source

pub fn expand_tabs(&self) -> bool

Expand tabs to spaces. Only for new inputs.

Source

pub fn set_glyph_ctrl(&mut self, show_ctrl: bool)

Show control characters when iterating glyphs.

Source

pub fn glyph_ctrl(&self) -> bool

Show glyphs for text-wrap.

Source

pub fn set_wrap_ctrl(&mut self, wrap_ctrl: bool)

Show glyphs for text-wrap.

Source

pub fn wrap_ctrl(&self) -> bool

Show control characters when iterating glyphs.

Source

pub fn set_glyph_line_break(&mut self, line_break: bool)

Handle line-breaks when iterating glyphs. If false everything is treated as one line.

Source

pub fn glyph_line_break(&self) -> bool

Handle line-breaks. If false everything is treated as one line.

Source§

impl<Store: TextStore + Default> TextCore<Store>

Source

pub fn set_clipboard(&mut self, clip: Option<Box<dyn Clipboard + 'static>>)

Clipboard

Source

pub fn clipboard(&self) -> Option<&dyn Clipboard>

Clipboard

Source§

impl<Store: TextStore + Default> TextCore<Store>

Source

pub fn set_undo_buffer(&mut self, undo: Option<Box<dyn UndoBuffer>>)

Undo

Source

pub fn set_undo_count(&mut self, n: u32)

Set undo count

Source

pub fn begin_undo_seq(&mut self)

Begin a sequence of changes that should be undone in one go.

Source

pub fn end_undo_seq(&mut self)

End a sequence of changes that should be undone in one go.

Source

pub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>

Undo

Source

pub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>

Undo

Source

pub fn undo(&mut self) -> bool

Undo last.

Source

pub fn redo(&mut self) -> bool

Redo last.

Source

pub fn recent_replay_log(&mut self) -> Vec<UndoEntry>

Get last replay recording.

Source

pub fn replay_log(&mut self, replay: &[UndoEntry])

Replay a recording of changes.

Source§

impl<Store: TextStore + Default> TextCore<Store>

Source

pub fn set_range_styles( &mut self, new_styles: Vec<(TextRange, usize)>, ) -> Result<(), TextError>

Set all styles.

The ranges are TextRanges. The usize value is the index of the actual style. Those are set with the widget.

Source

pub fn set_styles(&mut self, new_styles: Vec<(Range<usize>, usize)>)

Set all styles.

The ranges are byte-ranges. The usize value is the index of the actual style. Those are set with the widget.

Source

pub fn add_style(&mut self, range: Range<usize>, style: usize)

Add a style for the given byte-range.

The usize value is the index of the actual style. Those are set at the widget.

Source

pub fn remove_style(&mut self, range: Range<usize>, style: usize)

Remove a style for the given byte-range.

Range and style must match to be removed.

Source

pub fn styles_in( &self, range: Range<usize>, buf: &mut Vec<(Range<usize>, usize)>, )

Find all styles that touch the given range.

Source

pub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)

Finds all styles for the given position.

Source

pub fn style_match(&self, byte_pos: usize, style: usize) -> Option<Range<usize>>

Check if the given style applies at the position and return the complete range for the style.

Source

pub fn styles(&self) -> Option<impl Iterator<Item = (Range<usize>, usize)> + '_>

List of all styles.

Source§

impl<Store: TextStore + Default> TextCore<Store>

Source

pub fn set_cursor( &mut self, cursor: TextPosition, extend_selection: bool, ) -> bool

Set the cursor position. The value is capped to the number of text lines and the line-width for the given line.

Returns true, if the cursor actually changed.

Source

pub fn cursor(&self) -> TextPosition

Cursor position as grapheme-idx.

Source

pub fn anchor(&self) -> TextPosition

Selection anchor

Source

pub fn has_selection(&self) -> bool

Any text selection.

Source

pub fn set_selection( &mut self, anchor: TextPosition, cursor: TextPosition, ) -> bool

Select text. Anchor and cursor are capped to a valid value.

Source

pub fn select_all(&mut self) -> bool

Select all text.

Source

pub fn selection(&self) -> TextRange

Returns the selection as TextRange.

Source§

impl<Store: TextStore + Default> TextCore<Store>

Source

pub fn is_empty(&self) -> bool

Empty.

Source

pub fn byte_at(&self, pos: TextPosition) -> Result<Range<usize>, TextError>

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

Source

pub fn bytes_at_range( &self, range: TextRange, ) -> Result<Range<usize>, TextError>

Grapheme range to byte range.

Source

pub fn byte_pos(&self, byte: usize) -> Result<TextPosition, TextError>

Byte position to grapheme position. Returns the position that contains the given byte index.

Source

pub fn byte_range(&self, bytes: Range<usize>) -> Result<TextRange, TextError>

Byte range to grapheme range.

Source

pub fn str_slice(&self, range: TextRange) -> Result<Cow<'_, str>, TextError>

A range of the text as Cow<str>

Source

pub fn str_slice_byte( &self, range: Range<usize>, ) -> Result<Cow<'_, str>, TextError>

A range of the text as Cow<str>

Source

pub fn glyphs( &self, rows: Range<upos_type>, screen_offset: u16, screen_width: u16, ) -> Result<impl Iterator<Item = Glyph<'_>>, TextError>

👎Deprecated since 1.1.0: discontinued api

Iterator for the glyphs of the lines in range. Glyphs here a grapheme + display length.

Source

pub fn cache(&self) -> &Cache

Limited access to the cache. Gives only access to Debug.

Source

pub fn grapheme_at( &self, pos: TextPosition, ) -> Result<Option<Grapheme<'_>>, TextError>

Get the grapheme at the given position.

Source

pub fn text_graphemes( &self, pos: TextPosition, ) -> Result<impl Cursor<Item = Grapheme<'_>>, TextError>

Get a cursor over all the text with the current position set at pos.

Source

pub fn graphemes( &self, range: TextRange, pos: TextPosition, ) -> Result<Store::GraphemeIter<'_>, TextError>

Get a cursor over the text-range the current position set at pos.

Source

pub fn graphemes_byte( &self, range: Range<usize>, pos: usize, ) -> Result<Store::GraphemeIter<'_>, TextError>

Get a cursor over the text-range with the current position set at pos.

Source

pub fn line_at(&self, row: upos_type) -> Result<Cow<'_, str>, TextError>

Line as str.

  • row must be <= len_lines
Source

pub fn lines_at( &self, row: upos_type, ) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>

Iterate over text-lines, starting at row.

  • row must be <= len_lines
Source

pub fn line_graphemes( &self, row: upos_type, ) -> Result<Store::GraphemeIter<'_>, TextError>

Get the text for a line as iterator over the graphemes.

Source

pub fn line_width(&self, row: upos_type) -> Result<upos_type, TextError>

Line width as grapheme count. Excludes the terminating ‘\n’.

Source

pub fn len_lines(&self) -> upos_type

Number of lines.

Source§

impl<Store: TextStore + Default> TextCore<Store>

Source

pub fn clear(&mut self)

Clear the internal state.

Source

pub fn text(&self) -> &Store

Copy of the text-value.

Source

pub fn set_text(&mut self, t: Store) -> bool

Set the text as a TextStore Clears the styles. Caps cursor and anchor.

Source

pub fn insert_quotes( &mut self, sel: TextRange, c: char, ) -> Result<bool, TextError>

Auto-quote the selected text.

Source

pub fn insert_tab(&mut self, pos: TextPosition) -> Result<bool, TextError>

Insert a tab, either expanded or literally.

Source

pub fn insert_newline(&mut self, pos: TextPosition) -> Result<bool, TextError>

Insert a line break.

Source

pub fn insert_char( &mut self, pos: TextPosition, c: char, ) -> Result<bool, TextError>

Insert a character.

Source

pub fn insert_str( &mut self, pos: TextPosition, t: &str, ) -> Result<bool, TextError>

Insert a string at position.

Source

pub fn remove_prev_char(&mut self, pos: TextPosition) -> Result<bool, TextError>

Remove the previous character

Source

pub fn remove_next_char(&mut self, pos: TextPosition) -> Result<bool, TextError>

Remove the next characters.

Source

pub fn remove_char_range(&mut self, range: TextRange) -> Result<bool, TextError>

Remove a range. Put it into undo as ‘char-removed’.

Source

pub fn remove_str_range(&mut self, range: TextRange) -> Result<bool, TextError>

Remove a range Put it into undo as ‘str-removed’.

Source§

impl<Store: TextStore + Default> TextCore<Store>

Source

pub fn next_word_start( &self, pos: TextPosition, ) -> Result<TextPosition, TextError>

Find the start of the next word. If the position is at the start or inside a word, the same position is returned.

Source

pub fn next_word_end( &self, pos: TextPosition, ) -> Result<TextPosition, TextError>

Find the end of the next word. Skips whitespace first, then goes on until it finds the next whitespace.

Source

pub fn prev_word_start( &self, pos: TextPosition, ) -> Result<TextPosition, TextError>

Find the start of the prev word. Skips whitespace first, then goes on until it finds the next whitespace.

Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!

Source

pub fn prev_word_end( &self, pos: TextPosition, ) -> Result<TextPosition, TextError>

Find the end of the previous word. Word is everything that is not whitespace. Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!

Source

pub fn is_word_boundary(&self, pos: TextPosition) -> Result<bool, TextError>

Is the position at a word boundary?

Source

pub fn word_start(&self, pos: TextPosition) -> Result<TextPosition, TextError>

Find the start of the word at pos. Returns pos if the position is not inside a word.

Source

pub fn word_end(&self, pos: TextPosition) -> Result<TextPosition, TextError>

Find the end of the word at pos. Returns pos if the position is not inside a word.

Trait Implementations§

Source§

impl<Store: Clone> Clone for TextCore<Store>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Store: Debug> Debug for TextCore<Store>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Store> !Freeze for TextCore<Store>

§

impl<Store> !RefUnwindSafe for TextCore<Store>

§

impl<Store> !Send for TextCore<Store>

§

impl<Store> !Sync for TextCore<Store>

§

impl<Store> Unpin for TextCore<Store>
where Store: Unpin,

§

impl<Store> !UnwindSafe for TextCore<Store>

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