Skip to main content

TextArea

Struct TextArea 

Source
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

Source

pub fn new(initial_text: &str, wrap: WrapMode) -> Self

Create a new TextArea from initial_text, with cursor at (0, 0).

Source

pub fn text(&self) -> String

Return the full text, joining lines with '\n'.

Source

pub fn line_count(&self) -> usize

Return the number of lines.

Source

pub fn cursor(&self) -> (usize, usize)

Return the current cursor position as (row, col) in char indices.

Source

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.

Source

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.

Source

pub fn insert_newline(&mut self)

Split the current line at the cursor column, inserting a new line.

Commits any pending coalesced operation first.

Source

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.

Source

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.

Source

pub fn move_up(&mut self)

Move the cursor up one row, clamping column to the new line’s length.

Source

pub fn move_down(&mut self)

Move the cursor down one row, clamping column to the new line’s length.

Source

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.

Source

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.

Source

pub fn move_home(&mut self)

Move the cursor to column 0 (Home key).

Source

pub fn move_end(&mut self)

Move the cursor to the end of the current line (End key).

Source

pub fn move_doc_start(&mut self)

Move the cursor to the very beginning of the document.

Source

pub fn move_doc_end(&mut self)

Move the cursor to the very end of the document.

Source

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.

Source

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.

Source

pub fn select_all(&mut self)

Select all text; anchor at (0, 0), cursor at end of last line.

Source

pub fn selected_text(&self) -> Option<String>

Return the selected text, or None when the selection is collapsed.

Source

pub fn line_numbers(&self) -> Vec<usize>

Return a list of 1-based line numbers: [1, 2, …, line_count()].

Source

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.

Source

pub fn scroll_to_cursor(&mut self, line_height: f32, viewport_height: f32)

Adjust scroll_offset so that the cursor row is visible.

Source

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.

Source

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.

Source

pub fn is_modified(&self) -> bool

Return true if any edits have been recorded in the undo stack.

Source

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§

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.