TextInput

Struct TextInput 

Source
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: Lines

The 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: RopeIndex

Current 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.

https://html.spec.whatwg.org/multipage/#attr-fe-maxlength

§min_length: Option<Utf16CodeUnitLength>§was_last_change_by_set_content: bool

Was last change made by set_content?

§currently_dragging: bool

Whether or not we are currently dragging in this TextInput.

Implementations§

Source§

impl<T: ClipboardProvider> TextInput<T>

Source

pub fn new( lines: Lines, initial: DOMString, clipboard_provider: T, ) -> TextInput<T>

Instantiate a new text input control

Source

pub fn edit_point(&self) -> RopeIndex

Source

pub fn selection_origin(&self) -> Option<RopeIndex>

Source

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.

Source

pub fn selection_direction(&self) -> SelectionDirection

Source

pub fn set_max_length(&mut self, length: Option<Utf16CodeUnitLength>)

Source

pub fn set_min_length(&mut self, length: Option<Utf16CodeUnitLength>)

Source

pub(crate) fn was_last_change_by_set_content(&self) -> bool

Was last edit made by set_content?

Source

pub fn delete_char(&mut self, direction: Direction) -> bool

Remove a character at the current editing point

Returns true if any character was deleted

Source

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.

Source

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.

Source

pub(crate) fn selection_start_utf16(&self) -> Utf16CodeUnitLength

Source

fn selection_start_offset(&self) -> Utf8CodeUnitLength

The byte offset of the selection_start()

Source

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.

Source

pub(crate) fn selection_end_utf16(&self) -> Utf16CodeUnitLength

Source

pub fn selection_end_offset(&self) -> Utf8CodeUnitLength

The byte offset of the selection_end()

Source

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.

Source

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.

Source

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.

Source

pub(crate) fn selection_state(&self) -> SelectionState

The state of the current selection. Can be used to compare whether selection state has changed.

Source

fn assert_ok_selection(&self)

Source

fn selection_slice(&self) -> RopeSlice<'_>

Source

pub(crate) fn get_selection_text(&self) -> Option<String>

Source

fn selection_utf16_len(&self) -> Utf16CodeUnitLength

The length of the selected text in UTF-16 code units.

Source

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.

Source

pub fn modify_edit_point(&mut self, amount: isize, movement: RopeMovement)

Source

pub fn modify_selection(&mut self, amount: isize, movement: RopeMovement)

Source

pub fn modify_selection_or_edit_point( &mut self, amount: isize, movement: RopeMovement, select: Selection, )

Source

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.

Source

pub fn handle_return(&mut self) -> KeyReaction

Deal with a newline input.

Source

pub fn select_all(&mut self)

Select all text in the input control.

Source

pub fn clear_selection(&mut self)

Remove the current selection.

Source

pub(crate) fn clear_selection_to_end(&mut self)

Remove the current selection and set the edit point to the end of the content.

Source

pub(crate) fn clear_selection_to_start(&mut self)

Source

pub(crate) fn handle_keydown(&mut self, event: &KeyboardEvent) -> KeyReaction

Process a given KeyboardEvent and return an action for the caller to execute.

Source

pub fn handle_keydown_aux( &mut self, key: Key, mods: Modifiers, macos: bool, ) -> KeyReaction

Source

pub(crate) fn handle_compositionend( &mut self, event: &CompositionEvent, ) -> KeyReaction

Source

pub(crate) fn handle_compositionupdate( &mut self, event: &CompositionEvent, ) -> KeyReaction

Source

fn edit_point_for_mouse_event( &self, node: &Node, event: &MouseEvent, ) -> RopeIndex

Source

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.

Source

fn handle_mousedown(&mut self, node: &Node, mouse_event: &MouseEvent) -> bool

Handle a “mousedown” event that happened on this TextInput, belonging to the given Node.

Returns true if the TextInput changed at all or false otherwise.

Source

pub(crate) fn is_empty(&self) -> bool

Whether the content is empty.

Source

pub(crate) fn len_utf16(&self) -> Utf16CodeUnitLength

The total number of code units required to encode the content in utf16.

Source

pub fn get_content(&self) -> DOMString

Get the current contents of the text input. Multiple lines are joined by \n.

Source

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.

Source

pub fn set_selection_range_utf16( &mut self, start: Utf16CodeUnitLength, end: Utf16CodeUnitLength, direction: SelectionDirection, )

Source

pub fn set_selection_range_utf8( &mut self, start: Utf8CodeUnitLength, end: Utf8CodeUnitLength, direction: SelectionDirection, )

Source

pub(crate) fn handle_clipboard_event( &mut self, clipboard_event: &ClipboardEvent, ) -> ClipboardEventReaction

This implements step 3 onward from:

Earlier steps should have already been run by the callers.

Source

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>

Source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.
Source§

impl<T> Traceable for TextInput<T>

Source§

unsafe fn trace(&self, tracer: *mut JSTracer)

Trace self.

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> 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<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
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> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,