Struct script::textinput::TextInput

source ·
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: SelectionDirectionmultiline: bool

Is this a multiline input?

clipboard_provider: Tmax_length: Option<UTF16CodeUnits>

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<UTF16CodeUnits>was_last_change_by_set_content: bool

Was last change made by set_content?

Implementations

Instantiate a new text input control

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.

Was last edit made by set_content?

Remove a character at the current editing point

Insert a character at the current editing point

Insert a string at the current editing point

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.

The byte offset of the selection_start()

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.

The byte offset of the selection_end()

Whether or not there is an active selection (the selection may be zero-length)

Returns a tuple of (start, end) giving the bounds of the current selection. start is always less than or equal to end.

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.

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

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

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.

Return the length in bytes of the current line under the editing point.

Adjust the editing point position by a given number of lines. The resulting column is as close to the original column position as possible.

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.

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

Return whether to cancel the caret move

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.

Deal with a newline input.

Select all text in the input control.

Remove the current selection.

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

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

Whether the content is empty.

The length of the content in bytes.

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

The length of the content in Unicode code points.

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

Get a reference to the contents of a single-line text input. Panics if self is a multiline input.

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.

Convert a TextPoint into a byte offset from the start of the content.

Convert a byte offset from the start of the content into a TextPoint.

Set the edit point index position based off of a given grapheme cluster offset

Trait Implementations

Trace self.
Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert
Convert
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more