Skip to main content

TextArea

Struct TextArea 

Source
pub struct TextArea { /* private fields */ }
Expand description

A multi-line text editor widget

§Example

use revue::prelude::*;

let mut editor = TextArea::new()
    .content("Hello, World!\nLine 2")
    .line_numbers(true)
    .wrap(true);

// Handle key events
editor.handle_key(&Key::Char('a'));

§Keyboard Shortcuts

KeyAction
CharInsert character at cursor
EnterInsert newline
TabInsert tab (rendered as spaces based on tab_width)
BackspaceDelete character before cursor (or merge with previous line)
DeleteDelete character at cursor (or merge with next line)
LeftMove cursor left (clears selection)
RightMove cursor right (clears selection)
UpMove cursor up one line (clears selection)
DownMove cursor down one line (clears selection)
HomeMove cursor to start of line (clears selection)
EndMove cursor to end of line (clears selection)
PageUpMove cursor up 10 lines
PageDownMove cursor down 10 lines

Implementations§

Source§

impl TextArea

Source

pub fn get_syntax_language(&self) -> Language

Get the current highlighting language

Source

pub fn set_language(&mut self, language: Language)

Set the syntax highlighting language

Source

pub fn get_content(&self) -> String

Get the current text content

Source

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

Set the text content

Source

pub fn line_count(&self) -> usize

Get the number of lines

Source

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

Get the cursor position (primary cursor for backward compatibility)

Source

pub fn cursor_positions(&self) -> Vec<(usize, usize)>

Get all cursor positions

Source

pub fn cursor_count(&self) -> usize

Get the number of cursors

Source

pub fn set_cursor(&mut self, line: usize, col: usize)

Set the cursor position (primary cursor, clears secondary cursors)

Source

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

Get selected text (from primary cursor)

Source

pub fn delete_selection(&mut self)

Delete selected text (from primary cursor)

Source

pub fn has_selection(&self) -> bool

Check if primary cursor has a selection

Source

pub fn start_selection(&mut self)

Start selection at current cursor (primary)

Source

pub fn clear_selection(&mut self)

Clear selection (all cursors)

Source§

impl TextArea

Source

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

Insert a character at cursor

Source

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

Insert a string at cursor

Source

pub fn delete_char_before(&mut self)

Delete character before cursor (backspace)

Source

pub fn delete_char_at(&mut self)

Delete character at cursor (delete key)

Source

pub fn delete_line(&mut self)

Delete the current line

Source

pub fn duplicate_line(&mut self)

Duplicate the current line

Source§

impl TextArea

Source

pub fn open_find(&mut self)

Open find panel (Ctrl+F)

Source

pub fn open_replace(&mut self)

Open replace panel (Ctrl+H)

Source

pub fn close_find(&mut self)

Close find/replace panel

Source

pub fn is_find_open(&self) -> bool

Check if find panel is open

Source

pub fn find_state(&self) -> Option<&FindReplaceState>

Get find/replace state

Source

pub fn set_find_query(&mut self, query: &str)

Set find query and refresh matches

Source

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

Set replacement text

Source

pub fn find_next(&mut self)

Find next match (F3)

Source

pub fn find_previous(&mut self)

Find previous match (Shift+F3)

Source

pub fn replace_current(&mut self)

Replace current match

Source

pub fn replace_all(&mut self)

Replace all matches (Ctrl+Shift+H)

Source

pub fn toggle_case_sensitive(&mut self)

Toggle case sensitivity

Source

pub fn toggle_whole_word(&mut self)

Toggle whole word matching

Source

pub fn toggle_regex(&mut self)

Toggle regex mode

Source§

impl TextArea

Source

pub fn add_cursor_at(&mut self, line: usize, col: usize)

Add cursor at position (Alt+Click)

Source

pub fn add_cursor_above(&mut self)

Add cursor above current (Ctrl+Alt+Up)

Source

pub fn add_cursor_below(&mut self)

Add cursor below current (Ctrl+Alt+Down)

Source

pub fn clear_secondary_cursors(&mut self)

Clear all secondary cursors (Escape)

Source

pub fn select_next_occurrence(&mut self)

Select next occurrence of current word/selection (Ctrl+D)

Source§

impl TextArea

Source

pub fn move_left(&mut self)

Move cursor left

Source

pub fn move_right(&mut self)

Move cursor right

Source

pub fn move_up(&mut self)

Move cursor up

Source

pub fn move_down(&mut self)

Move cursor down

Source

pub fn move_home(&mut self)

Move to start of line

Source

pub fn move_end(&mut self)

Move to end of line

Source

pub fn move_document_start(&mut self)

Move to start of document

Source

pub fn move_document_end(&mut self)

Move to end of document

Source

pub fn move_word_left(&mut self)

Move cursor by word to the left

Source

pub fn move_word_right(&mut self)

Move cursor by word to the right

Source

pub fn page_up(&mut self, page_size: usize)

Page up

Source

pub fn page_down(&mut self, page_size: usize)

Page down

Source

pub fn select_all(&mut self)

Select all text

Source§

impl TextArea

Source

pub fn undo(&mut self)

Undo the last operation

Source

pub fn redo(&mut self)

Redo the last undone operation

Source§

impl TextArea

Source

pub fn new() -> Self

Create a new empty text area

Source

pub fn editor() -> Self

Create a TextArea pre-configured as a code editor with line numbers

Source

pub fn content(self, text: impl Into<String>) -> Self

Set initial content

Source

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

Show/hide line numbers

Source

pub fn wrap(self, wrap: bool) -> Self

Enable/disable word wrap

Source

pub fn read_only(self, read_only: bool) -> Self

Set read-only mode

Source

pub fn focused(self, focused: bool) -> Self

Set focused state

Source

pub fn tab_width(self, width: usize) -> Self

Set tab width

Source

pub fn placeholder(self, text: impl Into<String>) -> Self

Set placeholder text

Source

pub fn max_lines(self, max: usize) -> Self

Set maximum lines (0 = unlimited)

Source

pub fn min_height(self, height: u16) -> Self

Set minimum height in rows (0 = no constraint)

Defaults to 3. This prevents the TextArea from collapsing to zero height when used as an auto-sized child in a flex/stack layout.

Source

pub fn fg(self, color: Color) -> Self

Set text color

Source

pub fn bg(self, color: Color) -> Self

Set background color

Source

pub fn cursor_fg(self, color: Color) -> Self

Set cursor color

Source

pub fn selection_bg(self, color: Color) -> Self

Set selection background color

Source

pub fn line_number_fg(self, color: Color) -> Self

Set line number color

Source

pub fn match_highlight_bg(self, color: Color) -> Self

Set match highlight background color

Source

pub fn current_match_bg(self, color: Color) -> Self

Set current match highlight background color

Source

pub fn syntax(self, language: Language) -> Self

Enable syntax highlighting for a language

Source

pub fn syntax_with_theme(self, language: Language, theme: SyntaxTheme) -> Self

Enable syntax highlighting with a custom theme

Source

pub fn handle_key(&mut self, key: &Key) -> bool

Handle key event

Source§

impl TextArea

Source

pub fn element_id(self, id: impl Into<String>) -> Self

Set element ID for CSS selector (#id)

Source

pub fn class(self, class: impl Into<String>) -> Self

Add a CSS class

Source

pub fn classes<I, S>(self, classes: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple CSS classes

Trait Implementations§

Source§

impl Default for TextArea

Source§

fn default() -> Self

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

impl StyledView for TextArea

Source§

fn set_id(&mut self, id: impl Into<String>)

Set element ID
Source§

fn add_class(&mut self, class: impl Into<String>)

Add a CSS class
Source§

fn remove_class(&mut self, class: &str)

Remove a CSS class
Source§

fn toggle_class(&mut self, class: &str)

Toggle a CSS class
Source§

fn has_class(&self, class: &str) -> bool

Check if has class
Source§

impl View for TextArea

Source§

fn id(&self) -> Option<&str>

Get element ID (for CSS #id selectors) Read more
Source§

fn classes(&self) -> &[String]

Get CSS classes (for CSS .class selectors) Read more
Source§

fn meta(&self) -> WidgetMeta

Get widget metadata for DOM Read more
Source§

fn render(&self, ctx: &mut RenderContext<'_>)

Render the view to the given context Read more
Source§

fn widget_type(&self) -> &'static str

Get widget type name (for CSS type selectors) Read more
Source§

fn children(&self) -> &[Box<dyn View>]

Get child views (for container widgets) Read more

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.