pub struct TextAreaState {Show 20 fields
pub area: Rect,
pub inner: Rect,
pub rendered: Size,
pub screen_cursor: Option<(u16, u16)>,
pub hscroll: ScrollState,
pub vscroll: ScrollState,
pub sub_row_offset: u32,
pub dark_offset: (u16, u16),
pub scroll_to_cursor: Rc<Cell<bool>>,
pub value: TextCore<TextRope>,
pub move_col: Option<i16>,
pub auto_indent: bool,
pub auto_quote: bool,
pub text_wrap: TextWrap,
pub newline: String,
pub tab_width: u32,
pub expand_tabs: bool,
pub focus: FocusFlag,
pub mouse: MouseFlags,
pub non_exhaustive: NonExhaustive,
}Expand description
State & event handling.
Fields§
§area: RectThe whole area with block. read only renewed with each render.
inner: RectArea inside a possible block. read only renewed with each render.
rendered: SizeRendered dimension. This may differ from (inner.width, inner.height) if the text area has been relocated/clipped. This holds the original rendered dimension before any relocation/clipping.
screen_cursor: Option<(u16, u16)>Cursor position on the screen.
hscroll: ScrollStateHorizontal scroll. When text-break is active this value is ignored. read+write
vscroll: ScrollStateVertical offset. read+write
sub_row_offset: u32When text-break is active, this is the grapheme-offset into the first visible text-row where the display actually starts. read+write but it’s not advised.
dark_offset: (u16, u16)Dark offset due to clipping. Set during render. read only ignore this value.
scroll_to_cursor: Rc<Cell<bool>>The scroll offset will be adjusted to display the cursor. This will be the minimal adjustment, the cursor will stay at the same screen position if it’s already visible or appear at the start/end if it’s not. read only use scroll_cursor_to_visible.
value: TextCore<TextRope>Text edit core
move_col: Option<i16>Memory-column for up/down movement.
Up/down movement tries to place the cursor at this column, but might have to clip it, because the current line is too short.
This is kept as a relative screen-position. It may be less than 0, if the widget has been relocated. read only
auto_indent: boolauto indent active read only
auto_quote: boolquote selection active read only
text_wrap: TextWraptext breaking read only
newline: Stringnew-line bytes read only
tab_width: u32tab-width read only
expand_tabs: boolexpand tabs read only
focus: FocusFlagCurrent focus state. read + write But don’t write it.
mouse: MouseFlagsMouse selection in progress. read+write
non_exhaustive: NonExhaustiveImplementations§
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn new() -> TextAreaState
pub fn new() -> TextAreaState
New State.
Sourcepub fn named(name: &str) -> TextAreaState
pub fn named(name: &str) -> TextAreaState
New state with a focus name.
Sourcepub fn set_newline(&mut self, br: impl Into<String>)
pub fn set_newline(&mut self, br: impl Into<String>)
Sets the line ending 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.
Sourcepub fn set_auto_indent(&mut self, indent: bool)
pub fn set_auto_indent(&mut self, indent: bool)
Sets auto-indent on new-line.
Sourcepub fn set_auto_quote(&mut self, quote: bool)
pub fn set_auto_quote(&mut self, quote: bool)
Activates ‘add quotes to selection’.
Sourcepub fn set_tab_width(&mut self, tabs: u32)
pub fn set_tab_width(&mut self, tabs: u32)
Set tab-width.
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_show_ctrl(&mut self, show_ctrl: bool)
pub fn set_show_ctrl(&mut self, show_ctrl: bool)
Show glyphs for control characters.
Sourcepub fn set_wrap_ctrl(&mut self, wrap_ctrl: bool)
pub fn set_wrap_ctrl(&mut self, wrap_ctrl: bool)
Show glyphs for text-wrapping. Shows inserted line-breaks, zero-width space (U+200B) or the soft hyphen (U+00AD).
Sourcepub fn wrap_ctrl(&self) -> bool
pub fn wrap_ctrl(&self) -> bool
Show glyphs for text-wrapping. Shows inserted line-breaks, zero-width space (U+200B) or the soft hyphen (U+00AD).
Sourcepub fn set_text_wrap(&mut self, text_wrap: TextWrap)
pub fn set_text_wrap(&mut self, text_wrap: TextWrap)
Text wrapping mode.
-
TextWrap::Shift means no wrapping.
-
TextWrap::Hard hard-wraps at the right border.
-
TextWrap::Word(n) does word wrapping. n gives the size of the break-region close to the right border. The first space that falls in this region is taken as a break. If that is not possible this will break at the last space before. If there is no space it will hard-wrap the word.
Space is used as word separator. Hyphen will be used to break a word, and soft-hyphen and zero-width-space will be recognized too.
Sourcepub fn set_move_col(&mut self, col: Option<i16>)
pub fn set_move_col(&mut self, col: Option<i16>)
Extra column information for cursor movement.
The cursor position is capped to the current line length, so if you move up one row, you might end at a position left of the current column. If you move up once more you want to return to the original position. That’s what is stored here.
This stores the relative screen-column, it may be less than 0 if the widget has been relocated.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn set_clipboard(&mut self, clip: Option<impl Clipboard + 'static>)
pub fn set_clipboard(&mut self, clip: Option<impl Clipboard + 'static>)
Clipboard used. Default is to use the global_clipboard().
Sourcepub fn clipboard(&self) -> Option<&dyn Clipboard>
pub fn clipboard(&self) -> Option<&dyn Clipboard>
Clipboard used. Default is to use the global_clipboard().
Sourcepub fn copy_to_clip(&mut self) -> bool
pub fn copy_to_clip(&mut self) -> bool
Copy selection to clipboard.
Sourcepub fn cut_to_clip(&mut self) -> bool
pub fn cut_to_clip(&mut self) -> bool
Cut selection to clipboard.
Sourcepub fn paste_from_clip(&mut self) -> bool
pub fn paste_from_clip(&mut self) -> bool
Paste from clipboard.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn set_undo_buffer(&mut self, undo: Option<impl UndoBuffer + 'static>)
pub fn set_undo_buffer(&mut self, undo: Option<impl UndoBuffer + 'static>)
Set the undo buffer.
Default is an undo-buffer with 99 undoes.
Adjacent edits will be merged automatically into a single undo. (Type multiple characters, they will be undone in one go.)
Sourcepub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>
pub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>
Access the undo buffer.
Sourcepub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>
pub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>
Access the undo buffer.
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.
Call begin_undo_seq(), then call any edit-functions. When you are done call end_undo_seq(). Any changes will be undone in a single step.
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 recent_replay_log(&mut self) -> Vec<UndoEntry>
pub fn recent_replay_log(&mut self) -> Vec<UndoEntry>
Get all recent replay recordings. This log can be sent to a second TextAreaState and can be applied with replay_log().
There are some caveats.
Sourcepub fn replay_log(&mut self, replay: &[UndoEntry])
pub fn replay_log(&mut self, replay: &[UndoEntry])
Apply the replay recording.
There are some caveats.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn set_styles(&mut self, styles: Vec<(Range<usize>, usize)>)
pub fn set_styles(&mut self, styles: Vec<(Range<usize>, usize)>)
Set and replace all styles.
The ranges are byte-ranges into the text. There is no verification that the ranges fit the text.
Each byte-range maps to an index into the styles set with the widget.
Any style-idx that don’t have a match there are just ignored. You can use this to store other range based information. The ranges are corrected during edits, no need to recalculate everything after each keystroke.
But this is only a very basic correction based on insertions and deletes. If you use this for syntax-highlighting you probably need to rebuild the styles.
Sourcepub fn set_range_styles(
&mut self,
styles: Vec<(TextRange, usize)>,
) -> Result<(), TextError>
pub fn set_range_styles( &mut self, styles: Vec<(TextRange, usize)>, ) -> Result<(), TextError>
Set and replace all styles.
The ranges are TextRanges into the text. Each byte-range maps to an index into the styles set with the widget.
Any style-idx that don’t have a match there are just ignored. You can use this to store other range based information. The ranges are corrected during edits, no need to recalculate everything after each keystroke.
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 a byte-range.
The style-idx refers to one of the styles set with the widget. Missing styles are just ignored.
Sourcepub fn add_range_style(
&mut self,
range: impl Into<TextRange>,
style: usize,
) -> Result<(), TextError>
pub fn add_range_style( &mut self, range: impl Into<TextRange>, style: usize, ) -> Result<(), TextError>
Add a style for a TextRange. The style-nr refers to one of the styles set with the widget. Missing styles are just ignored.
Sourcepub fn remove_style(&mut self, range: Range<usize>, style: usize)
pub fn remove_style(&mut self, range: Range<usize>, style: usize)
Remove the exact byte-range and style.
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 remove_range_style(
&mut self,
range: impl Into<TextRange>,
style: usize,
) -> Result<(), TextError>
pub fn remove_range_style( &mut self, range: impl Into<TextRange>, style: usize, ) -> Result<(), TextError>
Remove the exact TextRange and 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)>)
All styles active at the given position.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn set_offset(&mut self, offset: (u32, u32)) -> bool
pub fn set_offset(&mut self, offset: (u32, u32)) -> bool
Set the offset for scrolling.
The offset uses usize, but it shouldn’t exceed (u32::MAX, u32::MAX). This is due to the internal ScrollState that only knows usize.
Sourcepub fn set_sub_row_offset(&mut self, sub_row_offset: u32) -> bool
pub fn set_sub_row_offset(&mut self, sub_row_offset: u32) -> bool
Scrolling uses the offset() for the start of the displayed text. When text-wrapping is active, this is not enough. This gives an extra offset into the first row where rendering should start.
You probably don’t want to set this value. Use set_cursor() instead, it will automatically scroll to make the cursor visible.
If you really want, pos_to_line_start() can help to find the start-position of a visual row. The x-value of the returned TextPosition is a valid value for this function.
Sourcepub fn sub_row_offset(&self) -> u32
pub fn sub_row_offset(&self) -> u32
Returns the extra offset into the first row where rendering starts. This is only valid if text-wrapping is active.
Returns the index of the column.
Sourcepub fn cursor(&self) -> TextPosition
pub fn cursor(&self) -> TextPosition
Cursor position.
Sourcepub fn set_cursor(
&mut self,
cursor: impl Into<TextPosition>,
extend_selection: bool,
) -> bool
pub fn set_cursor( &mut self, cursor: impl Into<TextPosition>, extend_selection: bool, ) -> bool
Set the cursor position and scroll the cursor to a visible offset.
Sourcepub fn anchor(&self) -> TextPosition
pub fn anchor(&self) -> TextPosition
Selection anchor.
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Has a selection?
Sourcepub fn set_selection(
&mut self,
anchor: impl Into<TextPosition>,
cursor: impl Into<TextPosition>,
) -> bool
pub fn set_selection( &mut self, anchor: impl Into<TextPosition>, cursor: impl Into<TextPosition>, ) -> bool
Set the selection, anchor and cursor are capped to a valid value. Scrolls the cursor to a visible position.
Sourcepub fn select_all(&mut self) -> bool
pub fn select_all(&mut self) -> bool
Select all. Scrolls the cursor to a visible position.
Sourcepub fn selected_text(&self) -> Cow<'_, str>
pub fn selected_text(&self) -> Cow<'_, str>
Selected text.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn str_slice_byte(&self, range: Range<usize>) -> Cow<'_, str>
pub fn str_slice_byte(&self, range: Range<usize>) -> Cow<'_, str>
Text slice as Cow<str>. Uses a byte range.
Panics for an invalid range.
Sourcepub fn try_str_slice_byte(
&self,
range: Range<usize>,
) -> Result<Cow<'_, str>, TextError>
pub fn try_str_slice_byte( &self, range: Range<usize>, ) -> Result<Cow<'_, str>, TextError>
Text slice as Cow<str>. Uses a byte range.
Sourcepub fn str_slice(&self, range: impl Into<TextRange>) -> Cow<'_, str>
pub fn str_slice(&self, range: impl Into<TextRange>) -> Cow<'_, str>
Text slice as Cow<str>
Panics for an invalid range.
Sourcepub fn try_str_slice(
&self,
range: impl Into<TextRange>,
) -> Result<Cow<'_, str>, TextError>
pub fn try_str_slice( &self, range: impl Into<TextRange>, ) -> Result<Cow<'_, str>, TextError>
Text slice as Cow<str>
Sourcepub fn line_width(&self, row: u32) -> u32
pub fn line_width(&self, row: u32) -> u32
Line width as grapheme count.
Panics for an invalid row.
Sourcepub fn line_at(&self, row: u32) -> Cow<'_, str>
pub fn line_at(&self, row: u32) -> Cow<'_, str>
Line as Cow<str>.
This contains the \n at the end.
Panics for an invalid row.
Sourcepub fn try_line_at(&self, row: u32) -> Result<Cow<'_, str>, TextError>
pub fn try_line_at(&self, row: u32) -> Result<Cow<'_, str>, TextError>
Line as Cow<str>.
This contains the \n at the end.
Sourcepub fn lines_at(&self, row: u32) -> impl Iterator<Item = Cow<'_, str>>
pub fn lines_at(&self, row: u32) -> impl Iterator<Item = Cow<'_, str>>
Iterate over text-lines, starting at offset.
Panics for an invalid row.
Sourcepub fn try_lines_at(
&self,
row: u32,
) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>
pub fn try_lines_at( &self, row: u32, ) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>
Iterate over text-lines, starting at offset.
Sourcepub fn line_graphemes(
&self,
row: u32,
) -> <TextRope as TextStore>::GraphemeIter<'_>
pub fn line_graphemes( &self, row: u32, ) -> <TextRope as TextStore>::GraphemeIter<'_>
Grapheme iterator for a given line. This contains the \n at the end.
Panics for an invalid row.
Sourcepub fn try_line_graphemes(
&self,
row: u32,
) -> Result<<TextRope as TextStore>::GraphemeIter<'_>, TextError>
pub fn try_line_graphemes( &self, row: u32, ) -> Result<<TextRope as TextStore>::GraphemeIter<'_>, TextError>
Grapheme iterator for a given line. This contains the \n at the end.
Sourcepub fn text_graphemes(
&self,
pos: impl Into<TextPosition>,
) -> <TextRope as TextStore>::GraphemeIter<'_>
pub fn text_graphemes( &self, pos: impl Into<TextPosition>, ) -> <TextRope as TextStore>::GraphemeIter<'_>
Get a cursor over all the text with the current position set at pos.
Panics for an invalid pos.
Sourcepub fn try_text_graphemes(
&self,
pos: impl Into<TextPosition>,
) -> Result<<TextRope as TextStore>::GraphemeIter<'_>, TextError>
pub fn try_text_graphemes( &self, pos: impl Into<TextPosition>, ) -> Result<<TextRope as TextStore>::GraphemeIter<'_>, TextError>
Get a cursor over all the text with the current position set at pos.
Sourcepub fn graphemes(
&self,
range: impl Into<TextRange>,
pos: impl Into<TextPosition>,
) -> <TextRope as TextStore>::GraphemeIter<'_>
pub fn graphemes( &self, range: impl Into<TextRange>, pos: impl Into<TextPosition>, ) -> <TextRope as TextStore>::GraphemeIter<'_>
Get a cursor over the text-range the current position set at pos.
Panics for an invalid pos.
Sourcepub fn try_graphemes(
&self,
range: impl Into<TextRange>,
pos: impl Into<TextPosition>,
) -> Result<<TextRope as TextStore>::GraphemeIter<'_>, TextError>
pub fn try_graphemes( &self, range: impl Into<TextRange>, pos: impl Into<TextPosition>, ) -> Result<<TextRope as TextStore>::GraphemeIter<'_>, TextError>
Get a cursor over the text-range the current position set at pos.
Sourcepub fn byte_at(&self, pos: impl Into<TextPosition>) -> Range<usize>
pub fn byte_at(&self, pos: impl Into<TextPosition>) -> Range<usize>
Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.
Panics for an invalid pos.
Sourcepub fn try_byte_at(
&self,
pos: impl Into<TextPosition>,
) -> Result<Range<usize>, TextError>
pub fn try_byte_at( &self, pos: impl Into<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: impl Into<TextRange>) -> Range<usize>
pub fn bytes_at_range(&self, range: impl Into<TextRange>) -> Range<usize>
Grapheme range to byte range.
Panics for an invalid range.
Sourcepub fn try_bytes_at_range(
&self,
range: impl Into<TextRange>,
) -> Result<Range<usize>, TextError>
pub fn try_bytes_at_range( &self, range: impl Into<TextRange>, ) -> Result<Range<usize>, TextError>
Grapheme range to byte range.
Sourcepub fn byte_pos(&self, byte: usize) -> TextPosition
pub fn byte_pos(&self, byte: usize) -> TextPosition
Byte position to grapheme position. Returns the position that contains the given byte index.
Panics for an invalid byte pos.
Sourcepub fn try_byte_pos(&self, byte: usize) -> Result<TextPosition, TextError>
pub fn try_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>) -> TextRange
pub fn byte_range(&self, bytes: Range<usize>) -> TextRange
Byte range to grapheme range.
Panics for an invalid range.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn insert_char(&mut self, c: char) -> bool
pub fn insert_char(&mut self, c: char) -> bool
Insert a character at the cursor position. Removes the selection and inserts the char.
This function can handle ‘\t’ and ‘\n’ well. They call insert_tab() and insert_newline() respectively.
Sourcepub fn insert_tab(&mut self) -> bool
pub fn insert_tab(&mut self) -> bool
Inserts tab at the current position. This respects the tab-width set.
If there is a text-selection the text-rows will be indented instead. This can be deactivated with auto_indent=false.
Sourcepub fn insert_backtab(&mut self) -> bool
pub fn insert_backtab(&mut self) -> bool
Dedent the selected text by tab-width. If there is no selection this does nothing.
This can be deactivated with auto_indent=false.
Sourcepub fn insert_str(&mut self, t: impl AsRef<str>) -> bool
pub fn insert_str(&mut self, t: impl AsRef<str>) -> bool
Insert text at the cursor position. Removes the selection and inserts the text.
Sourcepub fn insert_newline(&mut self) -> bool
pub fn insert_newline(&mut self) -> bool
Insert a line break at the cursor position.
If auto_indent is set the new line starts with the same indent as the current.
Sourcepub fn delete_range(&mut self, range: impl Into<TextRange>) -> bool
pub fn delete_range(&mut self, range: impl Into<TextRange>) -> bool
Deletes the given range.
Panics for an invalid range.
Sourcepub fn try_delete_range(
&mut self,
range: impl Into<TextRange>,
) -> Result<bool, TextError>
pub fn try_delete_range( &mut self, range: impl Into<TextRange>, ) -> Result<bool, TextError>
Deletes the given range.
Sourcepub fn duplicate_text(&mut self) -> bool
pub fn duplicate_text(&mut self) -> bool
Duplicates the selection or the current line. Returns true if there was any real change.
Sourcepub fn delete_line(&mut self) -> bool
pub fn delete_line(&mut self) -> bool
Deletes the current line. Returns true if there was any real change.
Sourcepub fn delete_next_char(&mut self) -> bool
pub fn delete_next_char(&mut self) -> bool
Deletes the next char or the current selection. Returns true if there was any real change.
Sourcepub fn delete_prev_char(&mut self) -> bool
pub fn delete_prev_char(&mut self) -> bool
Deletes the previous char or the selection. Returns true if there was any real change.
Sourcepub fn next_word_start(&self, pos: impl Into<TextPosition>) -> TextPosition
pub fn next_word_start(&self, pos: impl Into<TextPosition>) -> TextPosition
Find the start of the next word. If the position is at the start or inside a word, the same position is returned.
Panics for an invalid pos.
Sourcepub fn try_next_word_start(
&self,
pos: impl Into<TextPosition>,
) -> Result<TextPosition, TextError>
pub fn try_next_word_start( &self, pos: impl Into<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: impl Into<TextPosition>) -> TextPosition
pub fn next_word_end(&self, pos: impl Into<TextPosition>) -> TextPosition
Find the end of the next word. Skips whitespace first, then goes on until it finds the next whitespace.
Panics for an invalid pos.
Sourcepub fn try_next_word_end(
&self,
pos: impl Into<TextPosition>,
) -> Result<TextPosition, TextError>
pub fn try_next_word_end( &self, pos: impl Into<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: impl Into<TextPosition>) -> TextPosition
pub fn prev_word_start(&self, pos: impl Into<TextPosition>) -> TextPosition
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!
Panics for an invalid range.
Sourcepub fn try_prev_word_start(
&self,
pos: impl Into<TextPosition>,
) -> Result<TextPosition, TextError>
pub fn try_prev_word_start( &self, pos: impl Into<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: impl Into<TextPosition>) -> TextPosition
pub fn prev_word_end(&self, pos: impl Into<TextPosition>) -> TextPosition
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!
Panics for an invalid range.
Sourcepub fn try_prev_word_end(
&self,
pos: impl Into<TextPosition>,
) -> Result<TextPosition, TextError>
pub fn try_prev_word_end( &self, pos: impl Into<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: impl Into<TextPosition>) -> bool
pub fn is_word_boundary(&self, pos: impl Into<TextPosition>) -> bool
Is the position at a word boundary?
Panics for an invalid range.
Sourcepub fn try_is_word_boundary(
&self,
pos: impl Into<TextPosition>,
) -> Result<bool, TextError>
pub fn try_is_word_boundary( &self, pos: impl Into<TextPosition>, ) -> Result<bool, TextError>
Is the position at a word boundary?
Sourcepub fn word_start(&self, pos: impl Into<TextPosition>) -> TextPosition
pub fn word_start(&self, pos: impl Into<TextPosition>) -> TextPosition
Find the start of the word at pos. Returns pos if the position is not inside a word.
Panics for an invalid range.
Sourcepub fn try_word_start(
&self,
pos: impl Into<TextPosition>,
) -> Result<TextPosition, TextError>
pub fn try_word_start( &self, pos: impl Into<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: impl Into<TextPosition>) -> TextPosition
pub fn word_end(&self, pos: impl Into<TextPosition>) -> TextPosition
Find the end of the word at pos. Returns pos if the position is not inside a word.
Panics for an invalid range.
Sourcepub fn try_word_end(
&self,
pos: impl Into<TextPosition>,
) -> Result<TextPosition, TextError>
pub fn try_word_end( &self, pos: impl Into<TextPosition>, ) -> Result<TextPosition, TextError>
Find the end of the word at pos. Returns pos if the position is not inside a word.
Sourcepub fn delete_next_word(&mut self) -> bool
pub fn delete_next_word(&mut self) -> bool
Delete the next word. This alternates deleting the whitespace between words and the words themselves.
If there is a selection, removes only the selected text.
Sourcepub fn delete_prev_word(&mut self) -> bool
pub fn delete_prev_word(&mut self) -> bool
Deletes the previous word. This alternates deleting the whitespace between words and the words themselves.
If there is a selection, removes only the selected text.
Sourcepub fn search(&mut self, re: &str) -> Result<bool, TextError>
pub fn search(&mut self, re: &str) -> Result<bool, TextError>
Search for a regex.
Uses match_style for highlighting the matches. This doesn’t change the cursor/selection, use [move_to_next_match] or [move_to_prev_match] for this.
Return
Returns true if the search found anything.
Sourcepub fn move_to_next_match(&mut self) -> bool
pub fn move_to_next_match(&mut self) -> bool
Move to the next match.
Sourcepub fn move_to_prev_match(&mut self) -> bool
pub fn move_to_prev_match(&mut self) -> bool
Move to the next match.
Sourcepub fn clear_search(&mut self)
pub fn clear_search(&mut self)
Clear the search.
Sourcepub fn move_left(&mut self, n: u16, extend_selection: bool) -> bool
pub fn move_left(&mut self, n: u16, extend_selection: bool) -> bool
Move the cursor left. Scrolls the cursor to visible. Returns true if there was any real change.
Sourcepub fn move_right(&mut self, n: u16, extend_selection: bool) -> bool
pub fn move_right(&mut self, n: u16, extend_selection: bool) -> bool
Move the cursor right. Scrolls the cursor to visible. Returns true if there was any real change.
Sourcepub fn move_up(&mut self, n: u16, extend_selection: bool) -> bool
pub fn move_up(&mut self, n: u16, extend_selection: bool) -> bool
Move the cursor up. Scrolls the cursor to visible. Returns true if there was any real change.
Sourcepub fn move_down(&mut self, n: u16, extend_selection: bool) -> bool
pub fn move_down(&mut self, n: u16, extend_selection: bool) -> bool
Move the cursor down. Scrolls the cursor to visible. Returns true if there was any real change.
Sourcepub fn move_to_line_start(&mut self, extend_selection: bool) -> bool
pub fn move_to_line_start(&mut self, extend_selection: bool) -> bool
Move the cursor to the start of the line. Scrolls the cursor to visible. Returns true if there was any real change.
Sourcepub fn move_to_line_end(&mut self, extend_selection: bool) -> bool
pub fn move_to_line_end(&mut self, extend_selection: bool) -> bool
Move the cursor to the end of the line. Scrolls to visible, if necessary. Returns true if there was any real change.
Sourcepub fn move_to_start(&mut self, extend_selection: bool) -> bool
pub fn move_to_start(&mut self, extend_selection: bool) -> bool
Move the cursor to the document start.
Sourcepub fn move_to_end(&mut self, extend_selection: bool) -> bool
pub fn move_to_end(&mut self, extend_selection: bool) -> bool
Move the cursor to the document end.
Sourcepub fn move_to_screen_start(&mut self, extend_selection: bool) -> bool
pub fn move_to_screen_start(&mut self, extend_selection: bool) -> bool
Move the cursor to the start of the visible area.
Sourcepub fn move_to_screen_end(&mut self, extend_selection: bool) -> bool
pub fn move_to_screen_end(&mut self, extend_selection: bool) -> bool
Move the cursor to the end of the visible area.
Sourcepub fn move_to_next_word(&mut self, extend_selection: bool) -> bool
pub fn move_to_next_word(&mut self, extend_selection: bool) -> bool
Move the cursor to the next word.
Sourcepub fn move_to_prev_word(&mut self, extend_selection: bool) -> bool
pub fn move_to_prev_word(&mut self, extend_selection: bool) -> bool
Move the cursor to the previous word.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn relative_screen_to_pos(
&self,
scr_pos: (i16, i16),
) -> Option<TextPosition>
pub fn relative_screen_to_pos( &self, scr_pos: (i16, i16), ) -> Option<TextPosition>
Find the text-position for the widget-relative screen-position.
Sourcepub fn screen_to_pos(&self, scr_pos: (u16, u16)) -> Option<TextPosition>
pub fn screen_to_pos(&self, scr_pos: (u16, u16)) -> Option<TextPosition>
Find the text-position for an absolute screen-position.
Sourcepub fn pos_to_relative_screen(
&self,
pos: impl Into<TextPosition>,
) -> Option<(i16, i16)>
pub fn pos_to_relative_screen( &self, pos: impl Into<TextPosition>, ) -> Option<(i16, i16)>
Return the screen_position for the given text position relative to the origin of the widget.
This may be outside the visible area, if the text-area has been relocated. It may even be outside the screen, so this returns an (i16, i16).
If the text-position is outside the rendered area, this will return None.
Sourcepub fn pos_to_screen(&self, pos: impl Into<TextPosition>) -> Option<(u16, u16)>
pub fn pos_to_screen(&self, pos: impl Into<TextPosition>) -> Option<(u16, u16)>
Find the absolute screen-position for a text-position.
Sourcepub fn pos_to_line_start(&self, pos: impl Into<TextPosition>) -> TextPosition
pub fn pos_to_line_start(&self, pos: impl Into<TextPosition>) -> TextPosition
Return the starting position for the visible line containing the given position.
Sourcepub fn pos_to_line_end(&self, pos: impl Into<TextPosition>) -> TextPosition
pub fn pos_to_line_end(&self, pos: impl Into<TextPosition>) -> TextPosition
Return the end position for the visible line containing the given position.
Sourcepub fn set_screen_cursor(
&mut self,
cursor: (i16, i16),
extend_selection: bool,
) -> bool
pub fn set_screen_cursor( &mut self, cursor: (i16, i16), extend_selection: bool, ) -> bool
Set the cursor position from screen coordinates.
The cursor positions are relative to the inner rect. They may be negative too, this allows setting the cursor to a position that is currently scrolled away.
Sourcepub fn set_screen_cursor_words(
&mut self,
cursor: (i16, i16),
extend_selection: bool,
) -> bool
pub fn set_screen_cursor_words( &mut self, cursor: (i16, i16), extend_selection: bool, ) -> bool
Set the cursor position from screen coordinates, rounds the position to the next word start/end.
The cursor positions are relative to the inner rect. They may be negative too, this allows setting the cursor to a position that is currently scrolled away.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn vertical_max_offset(&self) -> u32
pub fn vertical_max_offset(&self) -> u32
Maximum offset that is accessible with scrolling.
This is set to len_lines - page_size for shift-mode,
and to len_lines for any wrapping-mode.
Sourcepub fn vertical_offset(&self) -> u32
pub fn vertical_offset(&self) -> u32
Current vertical offset.
Sourcepub fn vertical_page(&self) -> u32
pub fn vertical_page(&self) -> u32
Rendered height of the widget.
Sourcepub fn vertical_scroll(&self) -> u32
pub fn vertical_scroll(&self) -> u32
Suggested scroll per scroll-event.
Sourcepub fn horizontal_max_offset(&self) -> u32
pub fn horizontal_max_offset(&self) -> u32
Maximum horizontal offset.
This is set to 0 when text-wrapping is active. Otherwise, it can be set manually, but is always ignored by all scroll-functions. This widget doesn’t try to find an overall text-width.
It will be used to render the scrollbar though.
Sourcepub fn horizontal_offset(&self) -> u32
pub fn horizontal_offset(&self) -> u32
Current horizontal offset.
Sourcepub fn horizontal_page(&self) -> u32
pub fn horizontal_page(&self) -> u32
Rendered width of the text-area.
Sourcepub fn horizontal_scroll(&self) -> u32
pub fn horizontal_scroll(&self) -> u32
Suggested scroll-by per scroll-event.
Sourcepub fn set_vertical_offset(&mut self, row_offset: u32) -> bool
pub fn set_vertical_offset(&mut self, row_offset: u32) -> bool
Change the vertical offset. There is no limit to this offset.
Return
true if the offset changed at all.
Sourcepub fn set_horizontal_offset(&mut self, col_offset: u32) -> bool
pub fn set_horizontal_offset(&mut self, col_offset: u32) -> bool
Change the horizontal offset.
There is no limit to this offset. If there is text-wrapping this offset will be ignored.
Return
true if the offset changed at all.
Sourcepub fn scroll_cursor_to_visible(&mut self)
pub fn scroll_cursor_to_visible(&mut self)
Scroll that the cursor is visible.
This positioning happens with the next render.
All move-fn do this automatically.
Sourcepub fn scroll_to_pos(&mut self, pos: impl Into<TextPosition>) -> bool
pub fn scroll_to_pos(&mut self, pos: impl Into<TextPosition>) -> bool
Scrolls to make the given position visible.
Caveat
This function works correctly after the first render.
Sourcepub fn scroll_to_row(&mut self, pos: u32) -> bool
pub fn scroll_to_row(&mut self, pos: u32) -> bool
Scrolls to make the given row visible.
Adjusts the offset just enough to make this happen. Does nothing if the position is already visible.
Return
true if the offset changed.
Sourcepub fn scroll_to_col(&mut self, pos: u32) -> bool
pub fn scroll_to_col(&mut self, pos: u32) -> bool
Scroll to make the given column visible.
This scroll-offset is ignored if there is any text-wrapping.
Return
true if the offset changed.
Sourcepub fn scroll_up(&mut self, delta: u32) -> bool
pub fn scroll_up(&mut self, delta: u32) -> bool
Scroll up by delta rows.
Return
true if the offset changes.
Sourcepub fn scroll_down(&mut self, delta: u32) -> bool
pub fn scroll_down(&mut self, delta: u32) -> bool
Scroll down by delta rows.
Return
true if the offset changes.
Sourcepub fn scroll_left(&mut self, delta: u32) -> bool
pub fn scroll_left(&mut self, delta: u32) -> bool
Scroll left by delta columns.
This ignores the max_offset, as that is never correct anyway.
Return
true if the offset changes.
Caveat
Does nothing if text-wrapping is active.
Sourcepub fn scroll_right(&mut self, delta: u32) -> bool
pub fn scroll_right(&mut self, delta: u32) -> bool
Scroll right by delta columns.
This ignores the max_offset, as that is never correct anyway.
Return
trueif the offset changes.
Caveat
Does nothing if text-wrapping is active.
Trait Implementations§
Source§impl Clone for TextAreaState
impl Clone for TextAreaState
Source§fn clone(&self) -> TextAreaState
fn clone(&self) -> TextAreaState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextAreaState
impl Debug for TextAreaState
Source§impl Default for TextAreaState
impl Default for TextAreaState
Source§fn default() -> TextAreaState
fn default() -> TextAreaState
Source§impl HandleEvent<Event, MouseOnly, TextOutcome> for TextAreaState
impl HandleEvent<Event, MouseOnly, TextOutcome> for TextAreaState
Source§impl HandleEvent<Event, ReadOnly, TextOutcome> for TextAreaState
impl HandleEvent<Event, ReadOnly, TextOutcome> for TextAreaState
Source§impl HandleEvent<Event, Regular, TextOutcome> for TextAreaState
impl HandleEvent<Event, Regular, TextOutcome> for TextAreaState
Source§impl HasFocus for TextAreaState
impl HasFocus for TextAreaState
Source§fn build(&self, builder: &mut FocusBuilder)
fn build(&self, builder: &mut FocusBuilder)
Source§fn is_focused(&self) -> bool
fn is_focused(&self) -> bool
Source§fn lost_focus(&self) -> bool
fn lost_focus(&self) -> bool
Source§fn gained_focus(&self) -> bool
fn gained_focus(&self) -> bool
Source§impl HasScreenCursor for TextAreaState
impl HasScreenCursor for TextAreaState
Auto Trait Implementations§
impl !Freeze for TextAreaState
impl !RefUnwindSafe for TextAreaState
impl !Send for TextAreaState
impl !Sync for TextAreaState
impl Unpin for TextAreaState
impl !UnwindSafe for TextAreaState
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