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
impl InputState
Handles an action for the completion menu, if it exists.
Return true if the action was handled, otherwise false.
Sourcepub fn apply_lsp_edits(
&mut self,
text_edits: &Vec<TextEdit>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
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
impl InputState
Sourcepub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
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.
Sourcepub fn multi_line(self) -> Self
pub fn multi_line(self) -> Self
Set Input to use [InputMode::MultiLine
] mode.
Default rows is 2.
Sourcepub fn auto_grow(self, min_rows: usize, max_rows: usize) -> Self
pub fn auto_grow(self, min_rows: usize, max_rows: usize) -> Self
Set Input to use [InputMode::AutoGrow
] mode with min, max rows limit.
Sourcepub fn code_editor(self, language: impl Into<SharedString>) -> Self
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.
Sourcepub fn searchable(self, searchable: bool) -> Self
pub fn searchable(self, searchable: bool) -> Self
Set this input is searchable, default is false (Default true for Code Editor).
Sourcepub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
pub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
Set placeholder
Sourcepub fn line_number(self, line_number: bool) -> Self
pub fn line_number(self, line_number: bool) -> Self
Set enable/disable line number, only for [InputMode::CodeEditor
] mode.
Sourcepub fn set_line_number(
&mut self,
line_number: bool,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_line_number( &mut self, line_number: bool, _: &mut Window, cx: &mut Context<'_, Self>, )
Set line number, only for [InputMode::CodeEditor
] mode.
Sourcepub fn tab_size(self, tab: TabSize) -> Self
pub fn tab_size(self, tab: TabSize) -> Self
Set the tab size for the input.
Only for [InputMode::MultiLine
] and [InputMode::CodeEditor
] mode.
Sourcepub fn rows(self, rows: usize) -> Self
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
Sourcepub fn set_highlighter(
&mut self,
new_language: impl Into<SharedString>,
cx: &mut Context<'_, Self>,
)
pub fn set_highlighter( &mut self, new_language: impl Into<SharedString>, cx: &mut Context<'_, Self>, )
Set highlighter language for for [InputMode::CodeEditor
] mode.
pub fn diagnostics(&self) -> Option<&DiagnosticSet>
pub fn diagnostics_mut(&mut self) -> Option<&mut DiagnosticSet>
Sourcepub fn set_placeholder(
&mut self,
placeholder: impl Into<SharedString>,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_placeholder( &mut self, placeholder: impl Into<SharedString>, _: &mut Window, cx: &mut Context<'_, Self>, )
Set placeholder
Sourcepub fn set_value(
&mut self,
value: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn insert(
&mut self,
text: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn replace(
&mut self,
text: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn masked(self, masked: bool) -> Self
pub fn masked(self, masked: bool) -> Self
Set with password masked state.
Only for [InputMode::SingleLine
] mode.
Sourcepub fn set_masked(
&mut self,
masked: bool,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn clean_on_escape(self) -> Self
pub fn clean_on_escape(self) -> Self
Set true to clear the input by pressing Escape key.
Sourcepub fn soft_wrap(self, wrap: bool) -> Self
pub fn soft_wrap(self, wrap: bool) -> Self
Set the soft wrap mode for multi-line input, default is true.
Sourcepub fn set_soft_wrap(
&mut self,
wrap: bool,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn pattern(self, pattern: Regex) -> Self
pub fn pattern(self, pattern: Regex) -> Self
Set the regular expression pattern of the input field.
Only for [InputMode::SingleLine
] mode.
Sourcepub fn set_pattern(
&mut self,
pattern: Regex,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn validate(
self,
f: impl Fn(&str, &mut Context<'_, Self>) -> bool + 'static,
) -> Self
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.
Sourcepub fn set_loading(
&mut self,
loading: bool,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn default_value(self, value: impl Into<SharedString>) -> Self
pub fn default_value(self, value: impl Into<SharedString>) -> Self
Set the default value of the input field.
Sourcepub fn value(&self) -> SharedString
pub fn value(&self) -> SharedString
Return the value of the input field.
Sourcepub fn unmask_value(&self) -> SharedString
pub fn unmask_value(&self) -> SharedString
Return the value without mask.
Sourcepub fn cursor_position(&self) -> Position
pub fn cursor_position(&self) -> Position
Return the (0-based) Position
of the cursor.
Sourcepub fn set_cursor_position(
&mut self,
position: impl Into<Position>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn unselect(&mut self, _: &mut Window, cx: &mut Context<'_, Self>)
pub fn unselect(&mut self, _: &mut Window, cx: &mut Context<'_, Self>)
Unselects the currently selected text.
Sourcepub fn mask_pattern(self, pattern: impl Into<MaskPattern>) -> Self
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
pub fn set_mask_pattern( &mut self, pattern: impl Into<MaskPattern>, _: &mut Window, cx: &mut Context<'_, Self>, )
Trait Implementations§
Source§impl EntityInputHandler for InputState
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>,
)
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>,
)
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>>
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>
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>
InputHandler::text_for_range
for detailsSource§fn selected_text_range(
&mut self,
_ignore_disabled_input: bool,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<UTF16Selection>
fn selected_text_range( &mut self, _ignore_disabled_input: bool, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<UTF16Selection>
InputHandler::selected_text_range
for detailsSource§fn marked_text_range(
&self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<Range<usize>>
fn marked_text_range( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>
InputHandler::marked_text_range
for detailsSource§fn unmark_text(&mut self, _window: &mut Window, _cx: &mut Context<'_, Self>)
fn unmark_text(&mut self, _window: &mut Window, _cx: &mut Context<'_, Self>)
InputHandler::unmark_text
for detailsSource§fn character_index_for_point(
&mut self,
point: Point<Pixels>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<usize>
fn character_index_for_point( &mut self, point: Point<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>
InputHandler::character_index_for_point
for detailsSource§impl Focusable for InputState
impl Focusable for InputState
Source§fn focus_handle(&self, _cx: &App) -> FocusHandle
fn focus_handle(&self, _cx: &App) -> FocusHandle
Source§impl Render for InputState
impl Render for InputState
impl EventEmitter<InputEvent> for InputState
impl EventEmitter<NumberInputEvent> for InputState
Auto Trait Implementations§
impl Freeze for InputState
impl !RefUnwindSafe for InputState
impl !Send for InputState
impl !Sync for InputState
impl Unpin for InputState
impl !UnwindSafe for InputState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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