pub struct InputBaseState<M: InputModeKind> { /* private fields */ }Expand description
The shared text-editing engine behind crate::input::InputState,
crate::input::TextareaState and crate::input::EditorState.
M is the mode marker: it carries no data and only decides which methods
exist, so an ordinary input cannot reach the editor’s language features.
The three states are type aliases of this one, which is why this name is
public: an alias is only as usable as the type behind it, so hiding this
would leave InputState unable to do anything. Prefer naming the aliases
— write InputState, not InputBaseState<InputMode>.
Implementations§
Source§impl InputBaseState<EditorMode>
impl InputBaseState<EditorMode>
Sourcepub fn create_decorations_collection(
&mut self,
decorations: Vec<TextDecoration>,
cx: &mut Context<'_, Self>,
) -> TextDecorationCollection
pub fn create_decorations_collection( &mut self, decorations: Vec<TextDecoration>, cx: &mut Context<'_, Self>, ) -> TextDecorationCollection
Create an independently managed collection of text decorations.
This follows Monaco’s
createDecorationsCollection
ownership model. Ranges use UTF-8 byte offsets into Self::value.
Decoration ranges follow text edits and do not need to be set again
after each change. Insertions at a range boundary do not expand the
range, matching Monaco’s
NeverGrowsWhenTypingAtEdges
behavior. Decorations are not rendered while the input is masked.
Collections live until their InputBaseState is dropped.
Collections are layered in insertion order; the first collection wins
when overlapping decorations set the same HighlightStyle property.
Callers should avoid conflicting overlaps within one collection.
Source§impl InputBaseState<EditorMode>
impl InputBaseState<EditorMode>
Source§impl InputBaseState<EditorMode>
Indent guides are a code-editor affordance.
impl InputBaseState<EditorMode>
Indent guides are a code-editor affordance.
Sourcepub fn set_indent_guides(
&mut self,
indent_guides: bool,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_indent_guides( &mut self, indent_guides: bool, _: &mut Window, cx: &mut Context<'_, Self>, )
Set indent guides at runtime.
Source§impl<M: MultiLineMode> InputBaseState<M>
Tab size only means something where there is more than one line to indent.
impl<M: MultiLineMode> InputBaseState<M>
Tab size only means something where there is more than one line to indent.
pub fn set_tab_size(&mut self, tab: TabSize, cx: &mut Context<'_, Self>)
Source§impl InputBaseState<EditorMode>
impl InputBaseState<EditorMode>
pub fn perform_code_action( &mut self, item: &CodeActionItem, window: &mut Window, cx: &mut Context<'_, Self>, )
Source§impl InputBaseState<EditorMode>
impl InputBaseState<EditorMode>
pub fn clear_hover_state(&mut self, cx: &mut Context<'_, Self>)
Source§impl InputBaseState<EditorMode>
impl InputBaseState<EditorMode>
pub fn present_completion_items( &mut self, trigger_start_offset: usize, query: impl Into<String>, items: Vec<CompletionItem>, cx: &mut Context<'_, Self>, )
pub fn present_code_actions( &mut self, items: Vec<CodeActionItem>, cx: &mut Context<'_, Self>, )
pub fn present_hover( &mut self, symbol_range: Range<usize>, hover: Hover, cx: &mut Context<'_, Self>, )
pub fn present_diagnostic( &mut self, diagnostic: DiagnosticEntry, cx: &mut Context<'_, Self>, )
pub fn clear_diagnostic_popover(&mut self, cx: &mut Context<'_, Self>)
pub fn route_overlay_action( &mut self, action: Box<dyn Action>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> bool
pub fn set_overlay_action_handler( &mut self, handler: impl Fn(InputOverlayKind, Box<dyn Action>, &mut Window, &mut Context<'_, InputBaseState<EditorMode>>) -> bool + 'static, )
pub fn has_overlay_action_handler(&self) -> bool
pub fn dismiss_completion_overlay(&mut self, cx: &mut Context<'_, Self>)
pub fn dismiss_code_action_overlay(&mut self, cx: &mut Context<'_, Self>)
pub fn insert_completion( &mut self, item: &CompletionItem, fallback_range: Range<usize>, window: &mut Window, cx: &mut Context<'_, Self>, )
pub fn hover_popover(&self) -> Option<&HoverPopoverState>
pub fn dismiss_lsp_overlays(&mut self, cx: &mut Context<'_, Self>)
Source§impl InputBaseState<EditorMode>
impl InputBaseState<EditorMode>
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<M: InputModeKind> InputBaseState<M>
impl<M: InputModeKind> InputBaseState<M>
pub fn open_search(&mut self, replace_mode: bool, cx: &mut Context<'_, Self>)
pub fn search_session(&self) -> &SearchSession
Sourcepub fn is_replaceable(&self) -> bool
pub fn is_replaceable(&self) -> bool
Returns true if the search panel can replace the matches.
This is false when the input is not replaceable, or when it is
disabled or readonly.
pub fn set_search_query( &mut self, query: impl Into<String>, case_insensitive: bool, cx: &mut Context<'_, Self>, )
pub fn close_search(&mut self, cx: &mut Context<'_, Self>)
pub fn next_search_match( &mut self, cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>
pub fn previous_search_match( &mut self, cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>
pub fn replace_current_search_match( &mut self, replacement: &str, window: &mut Window, cx: &mut Context<'_, Self>, ) -> bool
pub fn replace_all_search_matches( &mut self, replacement: &str, window: &mut Window, cx: &mut Context<'_, Self>, ) -> usize
Source§impl<M: InputModeKind> InputBaseState<M>
impl<M: InputModeKind> InputBaseState<M>
pub fn input_bounds(&self) -> Bounds<Pixels>
pub fn text_bounds(&self) -> Option<Bounds<Pixels>>
pub fn diagnostic_popover(&self) -> Option<Rc<DiagnosticEntry>>
pub fn presentation(&self) -> InputPresentation
pub fn is_multi_line(&self) -> bool
Sourcepub fn is_single_line(&self) -> bool
pub fn is_single_line(&self) -> bool
Whether this input is a single-line text field. See Self::is_multi_line.
Sourcepub fn is_code_editor(&self) -> bool
pub fn is_code_editor(&self) -> bool
Whether this input is a source-code editor.
Sourcepub fn is_copyable(&self) -> bool
pub fn is_copyable(&self) -> bool
Whether the user is allowed to copy the selection out.
A masked input keeps its value out of the clipboard.
pub fn set_text_align( &mut self, text_align: TextAlign, cx: &mut Context<'_, Self>, )
Sourcepub fn toggle_masked(&mut self, _: &mut Window, cx: &mut Context<'_, Self>)
pub fn toggle_masked(&mut self, _: &mut Window, cx: &mut Context<'_, Self>)
Flip the password mask.
Setting the mask is a single-line method, but flipping it stays here:
the reveal button is rendered from the generic path, and it can only be
switched on through crate::input::InputState anyway.
Sets whether the context menu that shows on right-click is enabled.
The context menu is enabled by default. This value is ignored if a custom context menu builder is defined on the input.
Sourcepub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
pub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
Set placeholder
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 [LayoutMode::CodeEditor] mode.
Sourcepub fn set_highlighter_factory(
&mut self,
factory: InputHighlighterFactory,
cx: &mut Context<'_, Self>,
)
pub fn set_highlighter_factory( &mut self, factory: InputHighlighterFactory, cx: &mut Context<'_, Self>, )
Install the parser/highlighter adapter used by code-editor mode.
Sourcepub fn ensure_highlighter_factory(&mut self, factory: InputHighlighterFactory)
pub fn ensure_highlighter_factory(&mut self, factory: InputHighlighterFactory)
Install a default adapter without replacing an application-provided one.
pub fn set_editor_style(&mut self, style: InputEditorStyle)
pub fn apply_highlighter_fold_candidates( &mut self, candidates: Vec<FoldRange>, cx: &mut Context<'_, Self>, )
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.
For single-line inputs the caret is placed at the end of the text while
the view is scrolled back to the start, so a long value shows its
beginning instead of its tail (matching HTML <input>). Multi-line
inputs reset the selection to 0..0.
Sourcepub fn replace_all(
&mut self,
text: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn replace_all( &mut self, text: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )
Replace the entire text content while preserving undo history.
Unlike set_value, this method records the
replacement in the undo stack, allowing the user to undo/redo
the change. The selection is placed at the end of the new text
for single-line inputs, or cleared (0..0) for multi-line inputs.
Use this when programmatically replacing the full text but the user should still be able to undo the operation — e.g. formatting.
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.
pub fn set_disabled(&mut self, disabled: bool, cx: &mut Context<'_, Self>)
pub fn set_readonly(&mut self, readonly: bool, cx: &mut Context<'_, Self>)
Sourcepub fn is_editable(&self) -> bool
pub fn is_editable(&self) -> bool
Returns true if the user is allowed to change the text.
This is false when the input is disabled or readonly, the programmatic
APIs (e.g.: Self::set_value, Self::insert) are not limited by this.
Sourcepub fn clean_on_escape(self) -> Self
pub fn clean_on_escape(self) -> Self
Set true to clear the input by pressing Escape key.
pub fn set_clean_on_escape(&mut self, clean: bool)
pub fn set_submit_on_enter(&mut self, submit: bool, cx: &mut Context<'_, Self>)
Sourcepub fn set_show_whitespaces(
&mut self,
show: bool,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_show_whitespaces( &mut self, show: bool, _: &mut Window, cx: &mut Context<'_, Self>, )
Update whether to show whitespace characters.
Sourcepub fn scroll_beyond_last_line(self, rows: Option<usize>) -> Self
pub fn scroll_beyond_last_line(self, rows: Option<usize>) -> Self
Empty rows reserved below the last line of content (“scroll
beyond last line”), code-editor mode only. Mirrors VSCode’s
editor.scrollBeyondLastLine / Zed’s scroll_beyond_last_line.
None(default): half the viewport, floored at [BOTTOM_MARGIN_ROWS] line-heights.Some(0): no trailing space; the cursor sits flush with the last row at scroll-max.Some(n): exactlynrows.
Sourcepub fn set_scroll_beyond_last_line(
&mut self,
rows: Option<usize>,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_scroll_beyond_last_line( &mut self, rows: Option<usize>, _: &mut Window, cx: &mut Context<'_, Self>, )
Update Self::scroll_beyond_last_line after construction.
Sourcepub fn cursor_surrounding_lines(self, lines: Option<usize>) -> Self
pub fn cursor_surrounding_lines(self, lines: Option<usize>) -> Self
Minimum number of lines the cursor is kept clear of the viewport’s
top/bottom edge before auto-scroll engages. Mirrors VSCode’s
editor.cursorSurroundingLines / Zed’s vertical_scroll_margin.
Orthogonal to Self::scroll_beyond_last_line, which sizes the
empty region; this controls the cursor’s resting distance from the
edge.
None(default): [BOTTOM_MARGIN_ROWS] lines, falling back to one line on small viewports.Some(n): exactlynlines, clamped to half the viewport.
Sourcepub fn set_cursor_surrounding_lines(
&mut self,
lines: Option<usize>,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_cursor_surrounding_lines( &mut self, lines: Option<usize>, _: &mut Window, cx: &mut Context<'_, Self>, )
Update Self::cursor_surrounding_lines after construction.
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 as an owned string.
The string is materialized on each call. See Self::text for the
Rope the state owns, which is borrowed and costs nothing to read.
Sourcepub fn selected_value(&self) -> SharedString
pub fn selected_value(&self) -> SharedString
Return the portion of the value within the input field that is selected by the user, as an owned string.
The string is materialized on each call. See Self::selected_text
for the same selection borrowed out of the Rope the state owns.
Sourcepub fn unmask_value(&self) -> SharedString
pub fn unmask_value(&self) -> SharedString
Return the value without mask.
Sourcepub fn text(&self) -> &Rope
pub fn text(&self) -> &Rope
Return the text Rope of the input field.
Borrowed from the state, so reading even a large document copies
nothing. See Self::value when an owned string is wanted.
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 refresh(&mut self, cx: &mut Context<'_, Self>)
pub fn refresh(&mut self, cx: &mut Context<'_, Self>)
Refresh the input, so the next render re-runs syntax highlighting and the LSP providers, not just a redraw.
Assigning the lsp providers (or other render-affecting state) at
runtime does not take effect until the text next changes. Call this
afterwards to force the refresh on the next render.
input.update(cx, |state, cx| {
state.extras.lsp.hover_provider = Some(provider);
state.refresh(cx);
});pub fn clean(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
Sourcepub fn visible_row_range(&self) -> Option<Range<usize>>
pub fn visible_row_range(&self) -> Option<Range<usize>>
Visible row range in the last laid-out viewport, None before first layout.
Sourcepub fn scroll_offset(&self) -> Point<Pixels>
pub fn scroll_offset(&self) -> Point<Pixels>
Current scroll offset of the editor viewport.
Sourcepub fn set_scroll_offset(
&mut self,
offset: Point<Pixels>,
cx: &mut Context<'_, Self>,
)
pub fn set_scroll_offset( &mut self, offset: Point<Pixels>, cx: &mut Context<'_, Self>, )
Set scroll offset of the editor viewport.
The offset will be clamped to the valid range, and applied after the next layout.
Sourcepub fn line_height(&self) -> Option<Pixels>
pub fn line_height(&self) -> Option<Pixels>
Laid-out line height; None before first layout.
Sourcepub fn selected_range(&self) -> Range<usize> ⓘ
pub fn selected_range(&self) -> Range<usize> ⓘ
Returns the current selection as a byte range into the text.
The range is empty (start == end) when no text is selected; in
that case the offset equals cursor(). Byte offsets are measured
in the underlying rope’s byte units.
pub fn select_all(&mut self, _: &mut Window, cx: &mut Context<'_, Self>)
Sourcepub fn set_selected_range(
&mut self,
range: Range<usize>,
cx: &mut Context<'_, Self>,
)
pub fn set_selected_range( &mut self, range: Range<usize>, cx: &mut Context<'_, Self>, )
Set the selected range using UTF-8 byte offsets.
Non-empty ranges expand to character boundaries. Empty ranges remain empty and are clipped to the preceding character boundary.
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>, )
Sourcepub fn ensure_number_mask(&mut self)
pub fn ensure_number_mask(&mut self)
Apply the default numeric mask unless the caller explicitly selected a mask.
Sourcepub fn selected_text(&self) -> RopeSlice<'_>
pub fn selected_text(&self) -> RopeSlice<'_>
Return the selected portion of the text, borrowed out of the Rope
the state owns.
See Self::selected_value when an owned string is wanted.
Source§impl InputBaseState<InputMode>
Methods that only a single-line input offers.
impl InputBaseState<InputMode>
Methods that only a single-line input offers.
Sourcepub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
Create a single-line text input state.
Sourcepub fn step_by(
self,
f: impl Fn(f64, StepAction, &mut App) -> f64 + 'static,
) -> Self
pub fn step_by( self, f: impl Fn(f64, StepAction, &mut App) -> f64 + 'static, ) -> Self
Set a custom step function of the [super::NumberInput].
The f receives the current value and the StepAction, and returns
the step to apply, so the step can vary with the value.
§Example
// At the boundary 1.0 the step is 0.1 going down and 0.5 going up.
InputState::new(window, cx).step_by(|value, action, _cx| match action {
StepAction::Increment => if value < 1.0 { 0.1 } else { 0.5 },
StepAction::Decrement => if value <= 1.0 { 0.1 } else { 0.5 },
})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.
Sourcepub fn pattern(self, pattern: Regex) -> Self
pub fn pattern(self, pattern: Regex) -> Self
Set the regular expression pattern of the input field.
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.
Sourcepub fn validate(self, f: impl Fn(&str, &mut App) -> bool + 'static) -> Self
pub fn validate(self, f: impl Fn(&str, &mut App) -> bool + 'static) -> Self
Set the validation function of the input field.
pub fn set_validator( &mut self, validate: impl Fn(&str, &mut App) -> bool + 'static, _cx: &mut Context<'_, Self>, )
Sourcepub fn step(self, step: impl Into<NumberStep>) -> Self
pub fn step(self, step: impl Into<NumberStep>) -> Self
Set the step value of the [super::NumberInput] for increment/decrement.
If any of step, min, max is set, the [super::NumberInput] will
update the value internally (step by step, default 1, clamp to the
min/max range and emit InputEvent::Change) instead of emitting
super::NumberInputEvent::Step.
See also Self::step_by to calculate the step value
based on the current value.
Sourcepub fn min(self, min: f64) -> Self
pub fn min(self, min: f64) -> Self
Set the minimum value of the [super::NumberInput].
The value will be clamped to the minimum value on stepping and on
blur (only if the clamped value passes the pattern/validate check).
See also Self::step.
Sourcepub fn max(self, max: f64) -> Self
pub fn max(self, max: f64) -> Self
Set the maximum value of the [super::NumberInput].
The value will be clamped to the maximum value on stepping and on
blur (only if the clamped value passes the pattern/validate check).
See also Self::step.
Sourcepub fn set_step(
&mut self,
step: impl Into<Option<NumberStep>>,
_: &mut Window,
_: &mut Context<'_, Self>,
)
pub fn set_step( &mut self, step: impl Into<Option<NumberStep>>, _: &mut Window, _: &mut Context<'_, Self>, )
Update the step value after construction, None to fall back to
emitting super::NumberInputEvent::Step (if min, max are unset).
See Self::step and Self::step_by.
Sourcepub fn set_min(
&mut self,
min: Option<f64>,
_: &mut Window,
_: &mut Context<'_, Self>,
)
pub fn set_min( &mut self, min: Option<f64>, _: &mut Window, _: &mut Context<'_, Self>, )
Update the minimum value after construction. See Self::min.
Sourcepub fn set_max(
&mut self,
max: Option<f64>,
_: &mut Window,
_: &mut Context<'_, Self>,
)
pub fn set_max( &mut self, max: Option<f64>, _: &mut Window, _: &mut Context<'_, Self>, )
Update the maximum value after construction. See Self::max.
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 spinner at the input right.
Source§impl<M: MultiLineMode> InputBaseState<M>
Methods shared by the two multi-line modes, and reachable on neither a
single-line input nor anything else.
impl<M: MultiLineMode> InputBaseState<M>
Methods shared by the two multi-line modes, and reachable on neither a single-line input nor anything else.
pub fn set_searchable(&mut self, searchable: bool, cx: &mut Context<'_, Self>)
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, default is true.
Sourcepub fn set_wrapping_indent(
&mut self,
wrapping_indent: WrappingIndent,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_wrapping_indent( &mut self, wrapping_indent: WrappingIndent, _: &mut Window, cx: &mut Context<'_, Self>, )
Update how soft-wrapped continuation lines are indented.
Source§impl InputBaseState<TextareaMode>
Methods that only ordinary multi-line text offers.
impl InputBaseState<TextareaMode>
Methods that only ordinary multi-line text offers.
Sourcepub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
Create a multi-line text state.
Being multi-line is carried by the mode, not by the layout, so the default plain-text layout needs no adjustment here.
pub fn set_auto_grow( &mut self, min_rows: usize, max_rows: usize, cx: &mut Context<'_, Self>, )
pub fn set_rows(&mut self, rows: usize, cx: &mut Context<'_, Self>)
Source§impl InputBaseState<EditorMode>
Methods that only a source-code editor offers.
impl InputBaseState<EditorMode>
Methods that only a source-code editor offers.
Sourcepub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
Create a source-code editor state.
Default options: line numbers on, tab size 2 with soft tabs, indent
guides on, multi-line, and search enabled. Set the language for syntax
highlighting with Self::language; without one the text is shown
unhighlighted.
The editor aims at simple code editing or display, not at being a full-featured code editor. It offers syntax highlighting, auto indent, line numbers, and handles large text up to about 50K lines.
Sourcepub fn language(self, language: impl Into<SharedString>) -> Self
pub fn language(self, language: impl Into<SharedString>) -> Self
Set the language to highlight, e.g. "rust".
See Self::set_highlighter to change it after construction.
Sourcepub fn set_folding(
&mut self,
folding: bool,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_folding( &mut self, folding: bool, _: &mut Window, cx: &mut Context<'_, Self>, )
Set code folding at runtime.
When disabling, all existing folds are cleared.
Sourcepub fn unfold_at(
&mut self,
position: impl Into<Position>,
cx: &mut Context<'_, Self>,
) -> bool
pub fn unfold_at( &mut self, position: impl Into<Position>, cx: &mut Context<'_, Self>, ) -> bool
Unfold any folded ranges that hide the given position.
Use this to reveal a position before acting on it (e.g. before
Self::set_cursor_position, which stops at a fold boundary),
without touching folds elsewhere in the buffer. Fold candidates are
kept, so the opened ranges can be folded again from the gutter.
A fold keeps its own first and last line visible, so a position on either of them opens nothing. Nested folds all open, since opening only the outermost would leave the position hidden.
Returns whether any fold was opened.
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.
Trait Implementations§
Source§impl<M: InputModeKind> EntityInputHandler for InputBaseState<M>
impl<M: InputModeKind> EntityInputHandler for InputBaseState<M>
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_utf16is 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§fn paste(
&mut self,
item: ClipboardItem,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
fn paste( &mut self, item: ClipboardItem, window: &mut Window, cx: &mut Context<'_, Self>, )
InputHandler::paste for detailsSource§fn set_selected_text_range(
&mut self,
_range_utf16: Range<usize>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
)
fn set_selected_text_range( &mut self, _range_utf16: Range<usize>, _window: &mut Window, _cx: &mut Context<'_, Self>, )
InputHandler::set_selected_text_range for detailsSource§fn text_length_utf16(
&mut self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<usize>
fn text_length_utf16( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>
InputHandler::text_length_utf16 for detailsSource§fn accepts_text_input(
&self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> bool
fn accepts_text_input( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> bool
InputHandler::accepts_text_input for detailsSource§fn text_input_configuration(
&mut self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> TextInputConfiguration
fn text_input_configuration( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> TextInputConfiguration
InputHandler::text_input_configuration for detailsSource§fn text_input_editable_range(
&mut self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<Range<usize>>
fn text_input_editable_range( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>
InputHandler::text_input_editable_range for detailsimpl<M: InputModeKind> EventEmitter<InputEvent> for InputBaseState<M>
Source§impl<M: InputModeKind> Focusable for InputBaseState<M>
impl<M: InputModeKind> Focusable for InputBaseState<M>
Source§fn focus_handle(&self, _cx: &App) -> FocusHandle
fn focus_handle(&self, _cx: &App) -> FocusHandle
Source§impl<M: InputModeKind> Render for InputBaseState<M>
impl<M: InputModeKind> Render for InputBaseState<M>
Auto Trait Implementations§
impl<M> !Freeze for InputBaseState<M>
impl<M> !RefUnwindSafe for InputBaseState<M>
impl<M> !Send for InputBaseState<M>
impl<M> !Sync for InputBaseState<M>
impl<M> !UnwindSafe for InputBaseState<M>
impl<M> Unpin for InputBaseState<M>where
<M as InputModeKind>::Extras: Unpin,
Option<Rc<dyn Fn(InputOverlayKind, Box<dyn Action>, &mut Window, &mut Context<'_, InputBaseState<M>>) -> bool>>: Unpin,
impl<M> UnsafeUnpin for InputBaseState<M>where
<M as InputModeKind>::Extras: UnsafeUnpin,
Option<Rc<dyn Fn(InputOverlayKind, Box<dyn Action>, &mut Window, &mut Context<'_, InputBaseState<M>>) -> bool>>: UnsafeUnpin,
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> 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