pub struct TextInput<T: ClipboardProvider> {
rope: Rope,
mode: Lines,
edit_point: RopeIndex,
selection_origin: Option<RopeIndex>,
selection_direction: SelectionDirection,
clipboard_provider: T,
max_length: Option<Utf16CodeUnitLength>,
min_length: Option<Utf16CodeUnitLength>,
was_last_change_by_set_content: bool,
currently_dragging: bool,
}Expand description
Encapsulated state for handling keyboard input in a single or multiline text input control.
Fields§
§rope: Rope§mode: LinesThe type of TextInput this is. When in multi-line mode, the TextInput will
automatically split all inserted text into lines and incorporate them into
the Self::rope. When in single line mode, the inserted text will be stripped of
newlines.
edit_point: RopeIndexCurrent cursor input point
selection_origin: Option<RopeIndex>The current selection goes from the selection_origin until the edit_point. Note that the selection_origin may be after the edit_point, in the case of a backward selection.
selection_direction: SelectionDirection§clipboard_provider: T§max_length: Option<Utf16CodeUnitLength>The maximum number of UTF-16 code units this text input is allowed to hold.
min_length: Option<Utf16CodeUnitLength>§was_last_change_by_set_content: boolWas last change made by set_content?
currently_dragging: boolWhether or not we are currently dragging in this TextInput.
Implementations§
Source§impl<T: ClipboardProvider> TextInput<T>
impl<T: ClipboardProvider> TextInput<T>
Sourcepub fn new(
lines: Lines,
initial: DOMString,
clipboard_provider: T,
) -> TextInput<T>
pub fn new( lines: Lines, initial: DOMString, clipboard_provider: T, ) -> TextInput<T>
Instantiate a new text input control
pub fn edit_point(&self) -> RopeIndex
pub fn selection_origin(&self) -> Option<RopeIndex>
Sourcepub fn selection_origin_or_edit_point(&self) -> RopeIndex
pub fn selection_origin_or_edit_point(&self) -> RopeIndex
The selection origin, or the edit point if there is no selection. Note that the selection origin may be after the edit point, in the case of a backward selection.
pub fn selection_direction(&self) -> SelectionDirection
pub fn set_max_length(&mut self, length: Option<Utf16CodeUnitLength>)
pub fn set_min_length(&mut self, length: Option<Utf16CodeUnitLength>)
Sourcepub(crate) fn was_last_change_by_set_content(&self) -> bool
pub(crate) fn was_last_change_by_set_content(&self) -> bool
Was last edit made by set_content?
Sourcepub fn delete_char(&mut self, direction: Direction) -> bool
pub fn delete_char(&mut self, direction: Direction) -> bool
Remove a character at the current editing point
Returns true if any character was deleted
Sourcepub fn insert<S: Into<String>>(&mut self, string: S)
pub fn insert<S: Into<String>>(&mut self, string: S)
Insert a string at the current editing point or replace the selection if one exists.
Sourcepub fn selection_start(&self) -> RopeIndex
pub fn selection_start(&self) -> RopeIndex
The start of the selection (or the edit point, if there is no selection). Always less than or equal to selection_end(), regardless of the selection direction.
pub(crate) fn selection_start_utf16(&self) -> Utf16CodeUnitLength
Sourcefn selection_start_offset(&self) -> Utf8CodeUnitLength
fn selection_start_offset(&self) -> Utf8CodeUnitLength
The byte offset of the selection_start()
Sourcepub fn selection_end(&self) -> RopeIndex
pub fn selection_end(&self) -> RopeIndex
The end of the selection (or the edit point, if there is no selection). Always greater than or equal to selection_start(), regardless of the selection direction.
pub(crate) fn selection_end_utf16(&self) -> Utf16CodeUnitLength
Sourcepub fn selection_end_offset(&self) -> Utf8CodeUnitLength
pub fn selection_end_offset(&self) -> Utf8CodeUnitLength
The byte offset of the selection_end()
Sourcepub(crate) fn has_uncollapsed_selection(&self) -> bool
pub(crate) fn has_uncollapsed_selection(&self) -> bool
Whether or not there is an active uncollapsed selection. This means that the selection origin is set and it differs from the edit point.
Sourcepub(crate) fn sorted_selection_offsets_range(&self) -> Range<Utf8CodeUnitLength> ⓘ
pub(crate) fn sorted_selection_offsets_range(&self) -> Range<Utf8CodeUnitLength> ⓘ
Return the selection range as byte offsets from the start of the content.
If there is no selection, returns an empty range at the edit point.
Sourcepub(crate) fn sorted_selection_character_offsets_range(&self) -> Range<usize> ⓘ
pub(crate) fn sorted_selection_character_offsets_range(&self) -> Range<usize> ⓘ
Return the selection range as character offsets from the start of the content.
If there is no selection, returns an empty range at the edit point.
Sourcepub(crate) fn selection_state(&self) -> SelectionState
pub(crate) fn selection_state(&self) -> SelectionState
The state of the current selection. Can be used to compare whether selection state has changed.
fn assert_ok_selection(&self)
fn selection_slice(&self) -> RopeSlice<'_>
pub(crate) fn get_selection_text(&self) -> Option<String>
Sourcefn selection_utf16_len(&self) -> Utf16CodeUnitLength
fn selection_utf16_len(&self) -> Utf16CodeUnitLength
The length of the selected text in UTF-16 code units.
Sourcepub fn replace_selection(&mut self, insert: &DOMString)
pub fn replace_selection(&mut self, insert: &DOMString)
Replace the current selection with the given DOMString. If the Rope is in
single line mode this will strip newlines, as opposed to Self::set_content,
which does not.
pub fn modify_edit_point(&mut self, amount: isize, movement: RopeMovement)
pub fn modify_selection(&mut self, amount: isize, movement: RopeMovement)
pub fn modify_selection_or_edit_point( &mut self, amount: isize, movement: RopeMovement, select: Selection, )
Sourcefn update_selection_direction(&mut self)
fn update_selection_direction(&mut self)
Update the field selection_direction.
When the edit_point (or focus) is before the selection_origin (or anchor) you have a backward selection. Otherwise you have a forward selection.
Sourcepub fn handle_return(&mut self) -> KeyReaction
pub fn handle_return(&mut self) -> KeyReaction
Deal with a newline input.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text in the input control.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Remove the current selection.
Sourcepub(crate) fn clear_selection_to_end(&mut self)
pub(crate) fn clear_selection_to_end(&mut self)
Remove the current selection and set the edit point to the end of the content.
pub(crate) fn clear_selection_to_start(&mut self)
Sourcepub(crate) fn handle_keydown(&mut self, event: &KeyboardEvent) -> KeyReaction
pub(crate) fn handle_keydown(&mut self, event: &KeyboardEvent) -> KeyReaction
Process a given KeyboardEvent and return an action for the caller to execute.
pub fn handle_keydown_aux( &mut self, key: Key, mods: Modifiers, macos: bool, ) -> KeyReaction
pub(crate) fn handle_compositionend( &mut self, event: &CompositionEvent, ) -> KeyReaction
pub(crate) fn handle_compositionupdate( &mut self, event: &CompositionEvent, ) -> KeyReaction
fn edit_point_for_mouse_event( &self, node: &Node, event: &MouseEvent, ) -> RopeIndex
Sourcepub(crate) fn handle_mouse_event(
&mut self,
node: &Node,
mouse_event: &MouseEvent,
) -> bool
pub(crate) fn handle_mouse_event( &mut self, node: &Node, mouse_event: &MouseEvent, ) -> bool
Handle a mouse even that has happened in this TextInput. Returns true if the selection
in the input may have changed and false otherwise.
Sourcefn handle_mousedown(&mut self, node: &Node, mouse_event: &MouseEvent) -> bool
fn handle_mousedown(&mut self, node: &Node, mouse_event: &MouseEvent) -> bool
Sourcepub(crate) fn len_utf16(&self) -> Utf16CodeUnitLength
pub(crate) fn len_utf16(&self) -> Utf16CodeUnitLength
The total number of code units required to encode the content in utf16.
Sourcepub fn get_content(&self) -> DOMString
pub fn get_content(&self) -> DOMString
Get the current contents of the text input. Multiple lines are joined by \n.
Sourcepub fn set_content(&mut self, content: DOMString)
pub fn set_content(&mut self, content: DOMString)
Set the current contents of the text input. If this is control supports multiple lines, any \n encountered will be stripped and force a new logical line.
Note that when the Rope is in single line mode, this will not strip newlines.
Newline stripping only happens for incremental updates to the Rope as <input>
elements currently need to store unsanitized values while being created.
pub fn set_selection_range_utf16( &mut self, start: Utf16CodeUnitLength, end: Utf16CodeUnitLength, direction: SelectionDirection, )
pub fn set_selection_range_utf8( &mut self, start: Utf8CodeUnitLength, end: Utf8CodeUnitLength, direction: SelectionDirection, )
Sourcepub(crate) fn handle_clipboard_event(
&mut self,
clipboard_event: &ClipboardEvent,
) -> ClipboardEventReaction
pub(crate) fn handle_clipboard_event( &mut self, clipboard_event: &ClipboardEvent, ) -> ClipboardEventReaction
This implements step 3 onward from:
- https://www.w3.org/TR/clipboard-apis/#copy-action
- https://www.w3.org/TR/clipboard-apis/#cut-action
- https://www.w3.org/TR/clipboard-apis/#paste-action
Earlier steps should have already been run by the callers.
Sourcepub(crate) fn queue_input_event(
&self,
target: &EventTarget,
data: Option<String>,
is_composing: IsComposing,
input_type: InputType,
)
pub(crate) fn queue_input_event( &self, target: &EventTarget, data: Option<String>, is_composing: IsComposing, input_type: InputType, )
Trait Implementations§
Source§impl<T> MallocSizeOf for TextInput<T>where
T: MallocSizeOf + ClipboardProvider,
impl<T> MallocSizeOf for TextInput<T>where
T: MallocSizeOf + ClipboardProvider,
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl<T> Freeze for TextInput<T>where
T: Freeze,
impl<T> RefUnwindSafe for TextInput<T>where
T: RefUnwindSafe,
impl<T> Send for TextInput<T>where
T: Send,
impl<T> Sync for TextInput<T>where
T: Sync,
impl<T> Unpin for TextInput<T>where
T: Unpin,
impl<T> UnwindSafe for TextInput<T>where
T: UnwindSafe,
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> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
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