pub struct TextInput<T: ClipboardProvider> {
lines: Vec<DOMString>,
edit_point: TextPoint,
selection_origin: Option<TextPoint>,
selection_direction: SelectionDirection,
multiline: bool,
clipboard_provider: T,
max_length: Option<UTF16CodeUnits>,
min_length: Option<UTF16CodeUnits>,
was_last_change_by_set_content: bool,
}
Expand description
Encapsulated state for handling keyboard input in a single or multiline text input control.
Fields§
§lines: Vec<DOMString>
Current text input content, split across lines without trailing ‘\n’
edit_point: TextPoint
Current cursor input point
selection_origin: Option<TextPoint>
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
§multiline: bool
Is this a multiline input?
clipboard_provider: T
§max_length: Option<UTF16CodeUnits>
The maximum number of UTF-16 code units this text input is allowed to hold.
min_length: Option<UTF16CodeUnits>
§was_last_change_by_set_content: bool
Was last change made by set_content?
Implementations§
source§impl<T: ClipboardProvider> TextInput<T>
impl<T: ClipboardProvider> TextInput<T>
sourcepub fn new(
lines: Lines,
initial: DOMString,
clipboard_provider: T,
max_length: Option<UTF16CodeUnits>,
min_length: Option<UTF16CodeUnits>,
selection_direction: SelectionDirection,
) -> TextInput<T>
pub fn new( lines: Lines, initial: DOMString, clipboard_provider: T, max_length: Option<UTF16CodeUnits>, min_length: Option<UTF16CodeUnits>, selection_direction: SelectionDirection, ) -> TextInput<T>
Instantiate a new text input control
pub fn edit_point(&self) -> TextPoint
pub fn selection_origin(&self) -> Option<TextPoint>
sourcepub fn selection_origin_or_edit_point(&self) -> TextPoint
pub fn selection_origin_or_edit_point(&self) -> TextPoint
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<UTF16CodeUnits>)
pub fn set_min_length(&mut self, length: Option<UTF16CodeUnits>)
sourcepub fn was_last_change_by_set_content(&self) -> bool
pub fn was_last_change_by_set_content(&self) -> bool
Was last edit made by set_content?
sourcepub fn delete_char(&mut self, dir: Direction)
pub fn delete_char(&mut self, dir: Direction)
Remove a character at the current editing point
sourcepub fn insert_char(&mut self, ch: char)
pub fn insert_char(&mut self, ch: char)
Insert a character at the current editing point
sourcepub fn insert_string<S: Into<String>>(&mut self, s: S)
pub fn insert_string<S: Into<String>>(&mut self, s: S)
Insert a string at the current editing point
sourcepub fn selection_start(&self) -> TextPoint
pub fn selection_start(&self) -> TextPoint
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.
sourcepub fn selection_start_offset(&self) -> UTF8Bytes
pub fn selection_start_offset(&self) -> UTF8Bytes
The byte offset of the selection_start()
sourcepub fn selection_end(&self) -> TextPoint
pub fn selection_end(&self) -> TextPoint
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.
sourcepub fn selection_end_offset(&self) -> UTF8Bytes
pub fn selection_end_offset(&self) -> UTF8Bytes
The byte offset of the selection_end()
sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Whether or not there is an active selection (the selection may be zero-length)
sourcepub fn sorted_selection_bounds(&self) -> (TextPoint, TextPoint)
pub fn sorted_selection_bounds(&self) -> (TextPoint, TextPoint)
Returns a tuple of (start, end) giving the bounds of the current selection. start is always less than or equal to end.
sourcepub fn sorted_selection_offsets_range(&self) -> Range<UTF8Bytes>
pub fn sorted_selection_offsets_range(&self) -> Range<UTF8Bytes>
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 fn selection_state(&self) -> SelectionState
pub 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)
pub fn get_selection_text(&self) -> Option<String>
sourcefn selection_utf16_len(&self) -> UTF16CodeUnits
fn selection_utf16_len(&self) -> UTF16CodeUnits
The length of the selected text in UTF-16 code units.
sourcefn fold_selection_slices<B, F: FnMut(&mut B, &str)>(&self, acc: B, f: F) -> B
fn fold_selection_slices<B, F: FnMut(&mut B, &str)>(&self, acc: B, f: F) -> B
Run the callback on a series of slices that, concatenated, make up the selected text.
The accumulator acc
can be mutated by the callback, and will be returned at the end.
pub fn replace_selection(&mut self, insert: DOMString)
sourcepub fn current_line_length(&self) -> UTF8Bytes
pub fn current_line_length(&self) -> UTF8Bytes
Return the length in bytes of the current line under the editing point.
sourcepub fn adjust_vertical(&mut self, adjust: isize, select: Selection)
pub fn adjust_vertical(&mut self, adjust: isize, select: Selection)
Adjust the editing point position by a given number of lines. The resulting column is as close to the original column position as possible.
sourcepub fn adjust_horizontal(
&mut self,
adjust: UTF8Bytes,
direction: Direction,
select: Selection,
)
pub fn adjust_horizontal( &mut self, adjust: UTF8Bytes, direction: Direction, select: Selection, )
Adjust the editing point position by a given number of bytes. If the adjustment requested is larger than is available in the current line, the editing point is adjusted vertically and the process repeats with the remaining adjustment requested.
sourcepub fn adjust_horizontal_by_one(
&mut self,
direction: Direction,
select: Selection,
)
pub fn adjust_horizontal_by_one( &mut self, direction: Direction, select: Selection, )
Adjust the editing point position by exactly one grapheme cluster. If the edit point is at the beginning of the line and the direction is “Backward” or the edit point is at the end of the line and the direction is “Forward”, a vertical adjustment is made
sourcefn adjust_selection_for_horizontal_change(
&mut self,
adjust: Direction,
select: Selection,
) -> bool
fn adjust_selection_for_horizontal_change( &mut self, adjust: Direction, select: Selection, ) -> bool
Return whether to cancel the caret move
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.
fn perform_horizontal_adjustment( &mut self, adjust: UTF8Bytes, direction: Direction, select: 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 fn clear_selection_to_limit(&mut self, direction: Direction)
pub fn clear_selection_to_limit(&mut self, direction: Direction)
Remove the current selection and set the edit point to the end of the content.
pub fn adjust_horizontal_by_word( &mut self, direction: Direction, select: Selection, )
pub fn adjust_horizontal_to_line_end( &mut self, direction: Direction, select: Selection, )
pub fn adjust_horizontal_to_limit( &mut self, direction: Direction, select: Selection, )
sourcepub fn handle_keydown(&mut self, event: &KeyboardEvent) -> KeyReaction
pub 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 fn handle_compositionend(&mut self, event: &CompositionEvent) -> KeyReaction
sourcepub fn utf16_len(&self) -> UTF16CodeUnits
pub fn utf16_len(&self) -> UTF16CodeUnits
The total number of code units required to encode the content in utf16.
sourcepub fn char_count(&self) -> usize
pub fn char_count(&self) -> usize
The length of the content in Unicode code points.
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 single_line_content(&self) -> &DOMString
pub fn single_line_content(&self) -> &DOMString
Get a reference to the contents of a single-line text input. Panics if self is a multiline input.
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.
sourcefn text_point_to_offset(&self, text_point: &TextPoint) -> UTF8Bytes
fn text_point_to_offset(&self, text_point: &TextPoint) -> UTF8Bytes
Convert a TextPoint into a byte offset from the start of the content.
sourcefn offset_to_text_point(&self, abs_point: UTF8Bytes) -> TextPoint
fn offset_to_text_point(&self, abs_point: UTF8Bytes) -> TextPoint
Convert a byte offset from the start of the content into a TextPoint.
pub fn set_selection_range( &mut self, start: u32, end: u32, direction: SelectionDirection, )
sourcepub fn set_edit_point_index(&mut self, index: usize)
pub fn set_edit_point_index(&mut self, index: usize)
Set the edit point index position based off of a given grapheme cluster offset
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>
impl<T> !Sync for TextInput<T>
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