pub struct TextCore<Store> { /* private fields */ }Expand description
Core for text editing.
Implementations§
Source§impl<Store> TextCore<Store>
impl<Store> TextCore<Store>
pub fn new( undo: Option<Box<dyn UndoBuffer>>, clip: Option<Box<dyn Clipboard>>, ) -> TextCore<Store>
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.
Source§impl<Store> TextCore<Store>
impl<Store> 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> TextCore<Store>
impl<Store> TextCore<Store>
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 remove_style_fully(&mut self, style: usize)
pub fn remove_style_fully(&mut self, style: usize)
Remove all ranges for the given style.
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_in_match(
&self,
range: Range<usize>,
style: usize,
buf: &mut Vec<(Range<usize>, usize)>,
)
pub fn styles_in_match( &self, range: Range<usize>, style: 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> TextCore<Store>
impl<Store> 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> TextCore<Store>
impl<Store> 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 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<<Store as TextStore>::GraphemeIter<'_>, TextError>
pub fn text_graphemes( &self, pos: TextPosition, ) -> Result<<Store as TextStore>::GraphemeIter<'_>, 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 as TextStore>::GraphemeIter<'_>, TextError>
pub fn graphemes( &self, range: TextRange, pos: TextPosition, ) -> Result<<Store as TextStore>::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 as TextStore>::GraphemeIter<'_>, TextError>
pub fn graphemes_byte( &self, range: Range<usize>, pos: usize, ) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
Get a cursor over the text-range with the current position set at pos.
Sourcepub fn line_at(&self, row: u32) -> Result<Cow<'_, str>, TextError>
pub fn line_at(&self, row: u32) -> Result<Cow<'_, str>, TextError>
Line as str.
- row must be <= len_lines
Sourcepub fn lines_at(
&self,
row: u32,
) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>
pub fn lines_at( &self, row: u32, ) -> 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: u32,
) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
pub fn line_graphemes( &self, row: u32, ) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
Get the text for a line as iterator over the graphemes.
Source§impl<Store> TextCore<Store>
impl<Store> 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, cursor and anchor.
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.
Has no special handling for ‘\n’ and ‘\t’ and just adds them as they are. ‘\n’ is treated as line-break, but it might not be the correct byte-sequence for your platform.
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.
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