Skip to main content

TextArea

Struct TextArea 

Source
pub struct TextArea {
    pub buffer: TextBuffer,
    pub cursor: CursorState,
    pub undo_stack: UndoStack,
    pub scroll_offset: usize,
    pub show_line_numbers: bool,
    pub style: Style,
    pub cursor_style: Style,
    pub selection_style: Style,
    pub line_number_style: Style,
    /* private fields */
}
Expand description

A multi-line text editing widget.

Supports cursor movement, text selection, undo/redo, soft wrapping, optional line numbers, and pluggable syntax highlighting.

Fields§

§buffer: TextBuffer

The text content.

§cursor: CursorState

Cursor and selection state.

§undo_stack: UndoStack

Undo/redo history.

§scroll_offset: usize

Index of the first visible logical line.

§show_line_numbers: bool

Whether to show line numbers in the left gutter.

§style: Style

Base text style.

§cursor_style: Style

Style for the cursor cell.

§selection_style: Style

Style for selected text.

§line_number_style: Style

Style for line numbers.

Implementations§

Source§

impl TextArea

Source

pub fn new() -> Self

Create a new empty text area.

Source

pub fn from_text(text: &str) -> Self

Create a text area pre-filled with text.

Source

pub fn with_highlighter(self, h: Box<dyn Highlighter>) -> Self

Set a custom syntax highlighter.

Source

pub fn with_style(self, s: Style) -> Self

Set the base text style.

Source

pub fn with_line_numbers(self, show: bool) -> Self

Enable or disable line numbers.

Source

pub fn with_cursor_style(self, s: Style) -> Self

Set the cursor display style.

Source

pub fn with_selection_style(self, s: Style) -> Self

Set the selection display style.

Source

pub fn text(&self) -> String

Get the current text content as a string.

Source

pub fn insert_char(&mut self, ch: char)

Insert a character at the cursor position.

Source

pub fn insert_str(&mut self, text: &str)

Insert a string at the cursor position.

Source

pub fn delete_backward(&mut self)

Delete the character before the cursor (backspace).

Source

pub fn delete_forward(&mut self)

Delete the character at the cursor position (delete key).

Source

pub fn delete_selection(&mut self) -> bool

Delete the currently selected text, if any.

Returns true if a selection was deleted.

Source

pub fn new_line(&mut self)

Insert a newline at the cursor position.

Source

pub fn undo(&mut self)

Undo the last operation.

Source

pub fn redo(&mut self)

Redo the last undone operation.

Source

pub fn ensure_cursor_visible(&mut self, area_height: u16)

Ensure the cursor is within the visible area, adjusting scroll.

Trait Implementations§

Source§

impl Default for TextArea

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl InteractiveWidget for TextArea

Source§

fn handle_event(&mut self, event: &Event) -> EventResult

Handle an input event. Returns whether the event was consumed.
Source§

impl Widget for TextArea

Source§

fn render(&self, area: Rect, buf: &mut ScreenBuffer)

Render this widget into the given area of the buffer.

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, 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.