pub struct TextCore<Store> { /* private fields */ }
Expand description
Core for text editing.
Implementations§
Source§impl<Store: TextStore + Default> TextCore<Store>
impl<Store: TextStore + Default> TextCore<Store>
pub fn new( undo: Option<Box<dyn UndoBuffer>>, clip: Option<Box<dyn Clipboard>>, ) -> Self
Sourcepub fn set_newline(&mut self, br: String)
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.
Sourcepub fn set_tab_width(&mut self, tabs: u16)
pub fn set_tab_width(&mut self, tabs: u16)
Set the tab-width. Default is 8.
Sourcepub fn set_expand_tabs(&mut self, expand: bool)
pub fn set_expand_tabs(&mut self, expand: bool)
Expand tabs to spaces. Only for new inputs.
Sourcepub fn expand_tabs(&self) -> bool
pub fn expand_tabs(&self) -> bool
Expand tabs to spaces. Only for new inputs.
Sourcepub fn set_glyph_ctrl(&mut self, show_ctrl: bool)
pub fn set_glyph_ctrl(&mut self, show_ctrl: bool)
Show control characters when iterating glyphs.
Sourcepub fn glyph_ctrl(&self) -> bool
pub fn glyph_ctrl(&self) -> bool
Show glyphs for text-wrap.
Sourcepub fn set_wrap_ctrl(&mut self, wrap_ctrl: bool)
pub fn set_wrap_ctrl(&mut self, wrap_ctrl: bool)
Show glyphs for text-wrap.
Sourcepub fn set_glyph_line_break(&mut self, line_break: bool)
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.
Sourcepub fn glyph_line_break(&self) -> bool
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>
impl<Store: TextStore + Default> TextCore<Store>
Sourcepub fn set_undo_buffer(&mut self, undo: Option<Box<dyn UndoBuffer>>)
pub fn set_undo_buffer(&mut self, undo: Option<Box<dyn UndoBuffer>>)
Undo
Sourcepub fn set_undo_count(&mut self, n: u32)
pub fn set_undo_count(&mut self, n: u32)
Set undo count
Sourcepub fn begin_undo_seq(&mut self)
pub fn begin_undo_seq(&mut self)
Begin a sequence of changes that should be undone in one go.
Sourcepub fn end_undo_seq(&mut self)
pub fn end_undo_seq(&mut self)
End a sequence of changes that should be undone in one go.
Sourcepub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>
pub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>
Undo
Sourcepub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>
pub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>
Undo
Sourcepub fn recent_replay_log(&mut self) -> Vec<UndoEntry>
pub fn recent_replay_log(&mut self) -> Vec<UndoEntry>
Get last replay recording.
Sourcepub fn replay_log(&mut self, replay: &[UndoEntry])
pub fn replay_log(&mut self, replay: &[UndoEntry])
Replay a recording of changes.
Source§impl<Store: TextStore + Default> TextCore<Store>
impl<Store: TextStore + Default> TextCore<Store>
Sourcepub fn set_range_styles(
&mut self,
new_styles: Vec<(TextRange, usize)>,
) -> Result<(), TextError>
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.
Sourcepub fn set_styles(&mut self, new_styles: Vec<(Range<usize>, usize)>)
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.
Sourcepub fn add_style(&mut self, range: Range<usize>, style: usize)
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.
Sourcepub fn remove_style(&mut self, range: Range<usize>, style: usize)
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.
Sourcepub fn styles_in(
&self,
range: Range<usize>,
buf: &mut Vec<(Range<usize>, usize)>,
)
pub fn styles_in( &self, range: Range<usize>, buf: &mut Vec<(Range<usize>, usize)>, )
Find all styles that touch the given range.
Sourcepub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)
pub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)
Finds all styles for the given position.
Source§impl<Store: TextStore + Default> TextCore<Store>
impl<Store: TextStore + Default> TextCore<Store>
Sourcepub fn set_cursor(
&mut self,
cursor: TextPosition,
extend_selection: bool,
) -> bool
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.
Sourcepub fn cursor(&self) -> TextPosition
pub fn cursor(&self) -> TextPosition
Cursor position as grapheme-idx.
Sourcepub fn anchor(&self) -> TextPosition
pub fn anchor(&self) -> TextPosition
Selection anchor
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Any text selection.
Sourcepub fn set_selection(
&mut self,
anchor: TextPosition,
cursor: TextPosition,
) -> bool
pub fn set_selection( &mut self, anchor: TextPosition, cursor: TextPosition, ) -> bool
Select text. Anchor and cursor are capped to a valid value.
Sourcepub fn select_all(&mut self) -> bool
pub fn select_all(&mut self) -> bool
Select all text.
Source§impl<Store: TextStore + Default> TextCore<Store>
impl<Store: TextStore + Default> TextCore<Store>
Sourcepub fn byte_at(&self, pos: TextPosition) -> Result<Range<usize>, TextError>
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.
Sourcepub fn bytes_at_range(
&self,
range: TextRange,
) -> Result<Range<usize>, TextError>
pub fn bytes_at_range( &self, range: TextRange, ) -> Result<Range<usize>, TextError>
Grapheme range to byte range.
Sourcepub fn byte_pos(&self, byte: usize) -> Result<TextPosition, TextError>
pub fn byte_pos(&self, byte: usize) -> Result<TextPosition, TextError>
Byte position to grapheme position. Returns the position that contains the given byte index.
Sourcepub fn byte_range(&self, bytes: Range<usize>) -> Result<TextRange, TextError>
pub fn byte_range(&self, bytes: Range<usize>) -> Result<TextRange, TextError>
Byte range to grapheme range.
Sourcepub fn str_slice(&self, range: TextRange) -> Result<Cow<'_, str>, TextError>
pub fn str_slice(&self, range: TextRange) -> Result<Cow<'_, str>, TextError>
A range of the text as Cow<str>
Sourcepub fn str_slice_byte(
&self,
range: Range<usize>,
) -> Result<Cow<'_, str>, TextError>
pub fn str_slice_byte( &self, range: Range<usize>, ) -> Result<Cow<'_, str>, TextError>
A range of the text as Cow<str>
Sourcepub 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
pub fn glyphs( &self, rows: Range<upos_type>, screen_offset: u16, screen_width: u16, ) -> Result<impl Iterator<Item = Glyph<'_>>, TextError>
Iterator for the glyphs of the lines in range. Glyphs here a grapheme + display length.
Sourcepub fn grapheme_at(
&self,
pos: TextPosition,
) -> Result<Option<Grapheme<'_>>, TextError>
pub fn grapheme_at( &self, pos: TextPosition, ) -> Result<Option<Grapheme<'_>>, TextError>
Get the grapheme at the given position.
Sourcepub fn text_graphemes(
&self,
pos: TextPosition,
) -> Result<impl Cursor<Item = Grapheme<'_>>, TextError>
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.
Sourcepub fn graphemes(
&self,
range: TextRange,
pos: TextPosition,
) -> Result<Store::GraphemeIter<'_>, TextError>
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.
Sourcepub fn graphemes_byte(
&self,
range: Range<usize>,
pos: usize,
) -> Result<Store::GraphemeIter<'_>, TextError>
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.
Sourcepub fn line_at(&self, row: upos_type) -> Result<Cow<'_, str>, TextError>
pub fn line_at(&self, row: upos_type) -> Result<Cow<'_, str>, TextError>
Line as str.
- row must be <= len_lines
Sourcepub fn lines_at(
&self,
row: upos_type,
) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>
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
Sourcepub fn line_graphemes(
&self,
row: upos_type,
) -> Result<Store::GraphemeIter<'_>, TextError>
pub fn line_graphemes( &self, row: upos_type, ) -> Result<Store::GraphemeIter<'_>, TextError>
Get the text for a line as iterator over the graphemes.
Source§impl<Store: TextStore + Default> TextCore<Store>
impl<Store: TextStore + Default> TextCore<Store>
Sourcepub fn set_text(&mut self, t: Store) -> bool
pub fn set_text(&mut self, t: Store) -> bool
Set the text as a TextStore Clears the styles. Caps cursor and anchor.
Sourcepub fn insert_quotes(
&mut self,
sel: TextRange,
c: char,
) -> Result<bool, TextError>
pub fn insert_quotes( &mut self, sel: TextRange, c: char, ) -> Result<bool, TextError>
Auto-quote the selected text.
Sourcepub fn insert_tab(&mut self, pos: TextPosition) -> Result<bool, TextError>
pub fn insert_tab(&mut self, pos: TextPosition) -> Result<bool, TextError>
Insert a tab, either expanded or literally.
Sourcepub fn insert_newline(&mut self, pos: TextPosition) -> Result<bool, TextError>
pub fn insert_newline(&mut self, pos: TextPosition) -> Result<bool, TextError>
Insert a line break.
Sourcepub fn insert_char(
&mut self,
pos: TextPosition,
c: char,
) -> Result<bool, TextError>
pub fn insert_char( &mut self, pos: TextPosition, c: char, ) -> Result<bool, TextError>
Insert a character.
Sourcepub fn insert_str(
&mut self,
pos: TextPosition,
t: &str,
) -> Result<bool, TextError>
pub fn insert_str( &mut self, pos: TextPosition, t: &str, ) -> Result<bool, TextError>
Insert a string at position.
Sourcepub fn remove_prev_char(&mut self, pos: TextPosition) -> Result<bool, TextError>
pub fn remove_prev_char(&mut self, pos: TextPosition) -> Result<bool, TextError>
Remove the previous character
Sourcepub fn remove_next_char(&mut self, pos: TextPosition) -> Result<bool, TextError>
pub fn remove_next_char(&mut self, pos: TextPosition) -> Result<bool, TextError>
Remove the next characters.
Source§impl<Store: TextStore + Default> TextCore<Store>
impl<Store: TextStore + Default> TextCore<Store>
Sourcepub fn next_word_start(
&self,
pos: TextPosition,
) -> Result<TextPosition, TextError>
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.
Sourcepub fn next_word_end(
&self,
pos: TextPosition,
) -> Result<TextPosition, TextError>
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.
Sourcepub fn prev_word_start(
&self,
pos: TextPosition,
) -> Result<TextPosition, TextError>
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!
Sourcepub fn prev_word_end(
&self,
pos: TextPosition,
) -> Result<TextPosition, TextError>
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!
Sourcepub fn is_word_boundary(&self, pos: TextPosition) -> Result<bool, TextError>
pub fn is_word_boundary(&self, pos: TextPosition) -> Result<bool, TextError>
Is the position at a word boundary?
Sourcepub fn word_start(&self, pos: TextPosition) -> Result<TextPosition, TextError>
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.
Sourcepub fn word_end(&self, pos: TextPosition) -> Result<TextPosition, TextError>
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§
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> 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<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 more