InputState

Struct InputState 

Source
pub struct InputState {
    pub lsp: Lsp,
    /* private fields */
}
Expand description

InputState to keep editing state of the super::TextInput.

Fields§

§lsp: Lsp

Implementations§

Source§

impl InputState

Source

pub fn handle_action_for_context_menu( &mut self, action: Box<dyn Action>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> bool

Handles an action for the completion menu, if it exists.

Return true if the action was handled, otherwise false.

Source

pub fn apply_lsp_edits( &mut self, text_edits: &Vec<TextEdit>, window: &mut Window, cx: &mut Context<'_, Self>, )

Apply a list of lsp_types::TextEdit to mutate the text.

Source§

impl InputState

Source

pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self

Create a Input state with default [InputMode::SingleLine] mode.

See also: Self::multi_line, Self::auto_grow to set other mode.

Source

pub fn multi_line(self) -> Self

Set Input to use [InputMode::MultiLine] mode.

Default rows is 2.

Source

pub fn auto_grow(self, min_rows: usize, max_rows: usize) -> Self

Set Input to use [InputMode::AutoGrow] mode with min, max rows limit.

Source

pub fn code_editor(self, language: impl Into<SharedString>) -> Self

Set Input to use [InputMode::CodeEditor] mode.

Default options:

  • line_number: true
  • tab_size: 2
  • hard_tabs: false
  • height: full

If highlighter is None, will use the default highlighter.

Code Editor aim for help used to simple code editing or display, not a full-featured code editor.

§Features
  • Syntax Highlighting
  • Auto Indent
  • Line Number
  • Large Text support, up to 50K lines.
Source

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

Set this input is searchable, default is false (Default true for Code Editor).

Source

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

Set placeholder

Source

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

Set enable/disable line number, only for [InputMode::CodeEditor] mode.

Source

pub fn set_line_number( &mut self, line_number: bool, _: &mut Window, cx: &mut Context<'_, Self>, )

Set line number, only for [InputMode::CodeEditor] mode.

Source

pub fn tab_size(self, tab: TabSize) -> Self

Set the tab size for the input.

Only for [InputMode::MultiLine] and [InputMode::CodeEditor] mode.

Source

pub fn rows(self, rows: usize) -> Self

Set the number of rows for the multi-line Textarea.

This is only used when multi_line is set to true.

default: 2

Source

pub fn set_highlighter( &mut self, new_language: impl Into<SharedString>, cx: &mut Context<'_, Self>, )

Set highlighter language for for [InputMode::CodeEditor] mode.

Source

pub fn diagnostics(&self) -> Option<&DiagnosticSet>

Source

pub fn diagnostics_mut(&mut self) -> Option<&mut DiagnosticSet>

Source

pub fn set_placeholder( &mut self, placeholder: impl Into<SharedString>, _: &mut Window, cx: &mut Context<'_, Self>, )

Set placeholder

Source

pub fn set_value( &mut self, value: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )

Set the text of the input field.

And the selection_range will be reset to 0..0.

Source

pub fn insert( &mut self, text: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )

Insert text at the current cursor position.

And the cursor will be moved to the end of inserted text.

Source

pub fn replace( &mut self, text: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )

Replace text at the current cursor position.

And the cursor will be moved to the end of replaced text.

Source

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

Set with password masked state.

Only for [InputMode::SingleLine] mode.

Source

pub fn set_masked( &mut self, masked: bool, _: &mut Window, cx: &mut Context<'_, Self>, )

Set the password masked state of the input field.

Only for [InputMode::SingleLine] mode.

Source

pub fn clean_on_escape(self) -> Self

Set true to clear the input by pressing Escape key.

Source

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

Set the soft wrap mode for multi-line input, default is true.

Source

pub fn set_soft_wrap( &mut self, wrap: bool, _: &mut Window, cx: &mut Context<'_, Self>, )

Update the soft wrap mode for multi-line input, default is true.

Source

pub fn pattern(self, pattern: Regex) -> Self

Set the regular expression pattern of the input field.

Only for [InputMode::SingleLine] mode.

Source

pub fn set_pattern( &mut self, pattern: Regex, _window: &mut Window, _cx: &mut Context<'_, Self>, )

Set the regular expression pattern of the input field with reference.

Only for [InputMode::SingleLine] mode.

Source

pub fn validate( self, f: impl Fn(&str, &mut Context<'_, Self>) -> bool + 'static, ) -> Self

Set the validation function of the input field.

Only for [InputMode::SingleLine] mode.

Source

pub fn set_loading( &mut self, loading: bool, _: &mut Window, cx: &mut Context<'_, Self>, )

Set true to show indicator at the input right.

Only for [InputMode::SingleLine] mode.

Source

pub fn default_value(self, value: impl Into<SharedString>) -> Self

Set the default value of the input field.

Source

pub fn value(&self) -> SharedString

Return the value of the input field.

Source

pub fn unmask_value(&self) -> SharedString

Return the value without mask.

Source

pub fn text(&self) -> &Rope

Return the text Rope of the input field.

Source

pub fn cursor_position(&self) -> Position

Return the (0-based) Position of the cursor.

Source

pub fn set_cursor_position( &mut self, position: impl Into<Position>, window: &mut Window, cx: &mut Context<'_, Self>, )

Set (0-based) Position of the cursor.

This will move the cursor to the specified line and column, and update the selection range.

Source

pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Self>)

Focus the input field.

Source

pub fn cursor(&self) -> usize

Get byte offset of the cursor.

The offset is the UTF-8 offset.

Source

pub fn unselect(&mut self, _: &mut Window, cx: &mut Context<'_, Self>)

Unselects the currently selected text.

Source

pub fn mask_pattern(self, pattern: impl Into<MaskPattern>) -> Self

Set the mask pattern for formatting the input text.

The pattern can contain:

  • 9: Any digit or dot
  • A: Any letter
  • *: Any character
  • Other characters will be treated as literal mask characters

Example: “(999)999-999” for phone numbers

Source

pub fn set_mask_pattern( &mut self, pattern: impl Into<MaskPattern>, _: &mut Window, cx: &mut Context<'_, Self>, )

Trait Implementations§

Source§

impl EntityInputHandler for InputState

Source§

fn replace_text_in_range( &mut self, range_utf16: Option<Range<usize>>, new_text: &str, window: &mut Window, cx: &mut Context<'_, Self>, )

Replace text in range.

  • If the new text is invalid, it will not be replaced.
  • If range_utf16 is not provided, the current selected range will be used.
Source§

fn replace_and_mark_text_in_range( &mut self, range_utf16: Option<Range<usize>>, new_text: &str, new_selected_range_utf16: Option<Range<usize>>, window: &mut Window, cx: &mut Context<'_, Self>, )

Mark text is the IME temporary insert on typing.

Source§

fn bounds_for_range( &mut self, range_utf16: Range<usize>, bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Bounds<Pixels>>

Used to position IME candidates.

Source§

fn text_for_range( &mut self, range_utf16: Range<usize>, adjusted_range: &mut Option<Range<usize>>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<String>

Source§

fn selected_text_range( &mut self, _ignore_disabled_input: bool, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<UTF16Selection>

Source§

fn marked_text_range( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>

Source§

fn unmark_text(&mut self, _window: &mut Window, _cx: &mut Context<'_, Self>)

Source§

fn character_index_for_point( &mut self, point: Point<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>

Source§

impl Focusable for InputState

Source§

fn focus_handle(&self, _cx: &App) -> FocusHandle

Returns the focus handle associated with this view.
Source§

impl Render for InputState

Source§

fn render( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, ) -> impl IntoElement

Render this view into an element tree.
Source§

impl EventEmitter<InputEvent> for InputState

Source§

impl EventEmitter<NumberInputEvent> for InputState

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> 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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,