Skip to main content

TextFieldEditor

Struct TextFieldEditor 

Source
pub struct TextFieldEditor {
    pub meta: FieldMeta,
    pub editor: Editor<View, FormFieldHost>,
    pub validator: Option<Validator>,
    pub rows: u16,
    /* private fields */
}
Expand description

A text input field — either single-line or multi-line. Owns its own Editor<View, FormFieldHost> so the full vim grammar applies.

Two construction paths:

In standalone single-line mode, Enter is swallowed by TextFieldEditor::handle_input: there is no “next field” to jump to, and the surrounding host typically interprets Enter as “submit / commit” via its own dispatcher before the keystroke ever reaches the field. This keeps the buffer single-line by construction.

Fields§

§meta: FieldMeta§editor: Editor<View, FormFieldHost>§validator: Option<Validator>§rows: u16

Visible body height for multi-line fields. Single-line is 1.

Implementations§

Source§

impl TextFieldEditor

Source

pub fn new(single_line: bool) -> Self

Build a standalone vim-grammar text field with empty buffer. single_line=true suppresses Enter from inserting newlines and sets rows=1; multi-line fields default to rows=3. Hosts that want a different multi-line height should bump rows afterwards or use TextFieldEditor::with_meta.

Source

pub fn with_text(text: &str, single_line: bool) -> Self

Standalone variant pre-populated with text. Cursor lands at the end of the inserted content; mode is Normal.

Source

pub fn with_meta(meta: FieldMeta, rows: u16) -> Self

Form-style constructor: full metadata + render-height. The label / placeholder / required marker render via crate::Form’s ratatui adapter.

Source

pub fn with_validator(self, validator: Validator) -> Self

Attach a validator that runs on field-blur and on submit.

Source

pub fn with_initial(self, text: &str) -> Self

Pre-fill the editor’s buffer with text.

Source

pub fn buffer(&self) -> &View

Borrow the underlying View for span rendering, snapshots, or other read-only consumers.

Source

pub fn buffer_mut(&mut self) -> &mut View

Mutable buffer access. Rare — prefer TextFieldEditor::handle_input which routes through the vim FSM and keeps the cursor consistent.

Source

pub fn text(&self) -> String

Snapshot the buffer’s current text. Multi-line buffers join with '\n'. A single-line field returns only its first (visible) line, so a newline slipped in via o/O/paste can’t submit hidden multi-line data that the renderer never showed.

Source

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

Replace contents wholesale, e.g. when opening a prompt with a preset value. Drops the inner editor and rebuilds it; cursor lands at the end of the new content and mode is Normal.

Source

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

Cursor position as (row, col) in chars. Use directly to place the terminal cursor in the prompt’s render rect.

Source

pub fn coarse_mode(&self) -> CoarseMode

Discipline-agnostic coarse mode of the inner editor (Normal / Insert / Select / …).

A form field only ever needs “am I inserting text or not” — it has no business naming vim-specific states. Reading CoarseMode instead of VimMode keeps this widget usable under any keybinding discipline (#265 / #267).

Source

pub fn enter_insert_at_end(&mut self)

Force the inner editor into Insert mode at the end of the current line. Used by hosts that open a prompt and want the user typing immediately.

Source

pub fn enter_normal(&mut self)

Force the inner editor back to Normal mode (Esc).

Source

pub fn handle_input(&mut self, input: Input) -> bool

Forward a key event to the inner editor’s vim FSM. Returns true when the buffer’s dirty_gen advanced — useful for triggering incremental search on / ? prompts.

In single-line standalone mode, Enter while in Insert is swallowed: there is no next field to jump to. Hosts intercept Enter upstream as “submit”, so the field never sees it in practice; this guard is the belt-and-suspenders.

Source

pub fn dirty_gen(&self) -> u64

View dirty generation — bumps on every content edit.

Source

pub fn set_viewport_width(&mut self, width: u16)

Set the field’s host viewport width. The renderer should call this every frame so motions / scroll stay in-bounds.

Source

pub fn set_viewport_height(&mut self, height: u16)

Set the field’s host viewport height. Single-line fields pass 1.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more