pub struct TextArea {
pub dirty_paragraphs: HashSet<usize>,
/* private fields */
}Expand description
Multi-line text editor state (headless — no rendering).
Lines are stored individually without their trailing newline characters.
The logical text is reconstructed by TextArea::text.
Fields§
§dirty_paragraphs: HashSet<usize>Set of line indices that need re-shaping after an edit.
Implementations§
Source§impl TextArea
impl TextArea
Sourcepub fn new(initial_text: &str, wrap: WrapMode) -> Self
pub fn new(initial_text: &str, wrap: WrapMode) -> Self
Create a new TextArea from initial_text, with cursor at (0, 0).
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Return the number of lines.
Sourcepub fn cursor(&self) -> (usize, usize)
pub fn cursor(&self) -> (usize, usize)
Return the current cursor position as (row, col) in char indices.
Sourcepub fn commit_pending(&mut self)
pub fn commit_pending(&mut self)
Commit the pending operation (if any) onto the undo stack.
Consecutive typed characters are coalesced: if pending_op is
Insert at the same row and adjacent column, they are merged into one.
When committed, a new single-item group is pushed onto undo_stack.
Sourcepub fn insert_char(&mut self, ch: char)
pub fn insert_char(&mut self, ch: char)
Insert a character at the cursor position.
When ch == '\n', delegates to TextArea::insert_newline.
Otherwise inserts into the current line and advances the column.
Consecutive inserts on the same row at adjacent columns are coalesced
into a single undo group.
Sourcepub fn insert_newline(&mut self)
pub fn insert_newline(&mut self)
Split the current line at the cursor column, inserting a new line.
Commits any pending coalesced operation first.
Sourcepub fn delete_backward(&mut self)
pub fn delete_backward(&mut self)
Delete the character immediately before the cursor (Backspace).
When col == 0 and row > 0, joins the current line with the previous.
Commits any pending coalesced operation first.
Sourcepub fn delete_forward(&mut self)
pub fn delete_forward(&mut self)
Delete the character at the cursor position (Delete key).
When at the end of a line and there is a next line, joins them. Commits any pending coalesced operation first.
Sourcepub fn move_up(&mut self)
pub fn move_up(&mut self)
Move the cursor up one row, clamping column to the new line’s length.
Sourcepub fn move_down(&mut self)
pub fn move_down(&mut self)
Move the cursor down one row, clamping column to the new line’s length.
Sourcepub fn move_left(&mut self)
pub fn move_left(&mut self)
Move the cursor one character to the left.
When at column 0 and not on the first row, wraps to the end of the previous line.
Sourcepub fn move_right(&mut self)
pub fn move_right(&mut self)
Move the cursor one character to the right.
When at the end of a line and there is a next line, wraps to column 0 of the next line.
Sourcepub fn move_doc_start(&mut self)
pub fn move_doc_start(&mut self)
Move the cursor to the very beginning of the document.
Sourcepub fn move_doc_end(&mut self)
pub fn move_doc_end(&mut self)
Move the cursor to the very end of the document.
Sourcepub fn undo(&mut self) -> bool
pub fn undo(&mut self) -> bool
Undo the last edit group.
Commits any pending coalesced operation first, then pops the most recent entry from the undo stack, applies each op’s inverse in reverse order, and pushes the group to the redo stack.
Returns true when something was undone.
Sourcepub fn redo(&mut self) -> bool
pub fn redo(&mut self) -> bool
Redo the last undone edit group.
Commits any pending coalesced operation first, then pops from the redo stack, re-applies each op in forward order, and pushes the group back onto the undo stack.
Returns true when something was redone.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text; anchor at (0, 0), cursor at end of last line.
Sourcepub fn selected_text(&self) -> Option<String>
pub fn selected_text(&self) -> Option<String>
Return the selected text, or None when the selection is collapsed.
Sourcepub fn line_numbers(&self) -> Vec<usize>
pub fn line_numbers(&self) -> Vec<usize>
Return a list of 1-based line numbers: [1, 2, …, line_count()].
Sourcepub fn visible_range(
&self,
line_height: f32,
viewport_height: f32,
) -> Range<usize>
pub fn visible_range( &self, line_height: f32, viewport_height: f32, ) -> Range<usize>
Compute the visible line range for the given scroll offset and viewport.
first_line = floor(scroll_offset / line_height),
last_line = first_line + ceil(viewport_height / line_height),
clamped to 0..line_count.
Sourcepub fn scroll_to_cursor(&mut self, line_height: f32, viewport_height: f32)
pub fn scroll_to_cursor(&mut self, line_height: f32, viewport_height: f32)
Adjust scroll_offset so that the cursor row is visible.
Sourcepub fn display_lines_default(&self) -> Vec<String>
pub fn display_lines_default(&self) -> Vec<String>
Return display lines using the wrap mode configured at construction.
Delegates to TextArea::display_lines with self.wrap.
Sourcepub fn display_lines(&self, wrap: &WrapMode) -> Vec<String>
pub fn display_lines(&self, wrap: &WrapMode) -> Vec<String>
Return display lines after applying the wrap mode.
For WrapMode::Hard, lines are returned as-is.
For WrapMode::Soft, each logical line is split into
visual lines using an estimated char width of max_width / 8.0.
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Return true if any edits have been recorded in the undo stack.
Sourcepub fn shaped_paragraphs(
&mut self,
pipeline: &mut TextPipeline,
style: &TextStyle,
) -> Vec<ShapedText>
pub fn shaped_paragraphs( &mut self, pipeline: &mut TextPipeline, style: &TextStyle, ) -> Vec<ShapedText>
Shape all dirty paragraphs using pipeline and style, then return
the full per-line shaped-text cache.
Only lines listed in dirty_paragraphs are re-shaped; all other lines
are returned from the cache without re-shaping. Lines that could not be
shaped (e.g. because the pipeline reported an error) are represented as
an empty crate::ShapedText.
After this call dirty_paragraphs is cleared.
Auto Trait Implementations§
impl Freeze for TextArea
impl RefUnwindSafe for TextArea
impl Send for TextArea
impl Sync for TextArea
impl Unpin for TextArea
impl UnsafeUnpin for TextArea
impl UnwindSafe for TextArea
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> 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