69
Forinputp434
elements, calling these methods while theydon't applyp437
, and setting these attributes while theydon't applyp437
, must throw an
"InvalidStateError"
DOMException
; and getting these attributes while theydon't applyp437
must return null. Otherwise, they must act as
described below.
Forinputp434
elements, these methods and attributes must operate on the element'svaluep508
. Fortextareap489
elements, these methods and
attributes must operate on the element'sraw valuep490
.
Where possible, user interface features for changing the text selection ininputp434
andtextareap489
elements must be implemented in terms of
the DOM API described in this section, so that, e.g., all the same events fire.
The selections ofinputp434
andtextareap489
elements have adirection, which is eitherforward,backward, ornone. This direction is set when
the user manipulates the selection. The exact meaning of the selection direction depends on the platform.
Theselect()method must cause the contents of the text field to be fully selected, with the selection direction being none, if the platform support
selections with the directionnone, or otherwiseforward. The user agent must thenqueue a taskp843
tofire a simple eventp854
that bubbles named
selectp1155
at the element, using theuser interaction task sourcep846
as the task source.
In the case ofinputp434
elements, if the control has no text field, then the method must do nothing.
TheselectionStartattribute must, on getting, return the offset (in logical order) to the character that immediately follows the start of the
selection. If there is no selection, then it must return the offset (in logical order) to the character that immediately follows the text entry cursor.
On setting, it must act as if thesetSelectionRange()p530
method had been called, with the new value as the first argument; the current value of
theselectionEndp530
attribute as the second argument, unless the current value of theselectionEndp530
is less than the new value, in which
case the second argument must also be the new value; and the current value of theselectionDirectionp530
as the third argument.
Can be set, to change the direction of the selection.
The possible values are "forward", "backward", and "none".
element.setSelectionRangep530(start,end[,direction] )
Changes the selection to cover the given substring in the given direction. If the direction is omitted, it will be reset to be the platform
default (none or forward).
element.setRangeTextp530(replacement[,start,end[,selectionMode] ] )
Replaces a range of text with the new text. If thestartandendarguments are not provided, the range is assumed to be the selection.
The final argument determines how the selection should be set after the text has been replaced. The possible values are:
"selectp530"
Selects the newly inserted text.
"startp530"
Moves the selection to just before the inserted text.
"endp530"
Moves the selection to just after the selected text.
"preservep530"
Attempts to preserve the selection. This is the default.
On Windows, the direction indicates the position of the caret relative to the selection: aforwardselection has the caret at the end of the
selection and abackwardselection has the caret at the start of the selection. Windows has nononedirection. On Mac, the direction
indicates which end of the selection is affected when the user adjusts the size of the selection using the arrow keys with the Shift modifier:
the forward direction means the end of the selection is modified, and the backwards direction means the start of the selection is modified.
The none direction is the default on Mac, it indicates that no particular direction has yet been selected. The user sets the direction implicitly
when first adjusting the selection, based on which directional arrow key was used.
Note
For instance, in a user agent where<input type=color>p455
is rendered as a colour well with a picker, as opposed to a text field
accepting a hexadecimal colour code, there would be no text field, and thus nothing to select, and thus calls to the method are ignored.
Example
529