@@ -44981,9 +44981,9 @@ interface <dfn>HTMLInputElement</dfn> : <span>HTMLElement</span> {
4498144981 data-x="concept-input-apply">applies</span> to the element, and false otherwise.</p></li>
4498244982
4498344983 <li><p>If <var>previouslySelectable</var> is false and <var>nowSelectable</var> is true, set the
44984- element's text entry cursor position to the beginning of the text control, and <span
44985- data-x="set the selection direction">set its selection direction</span> to "<code
44986- data-x="">none</code>".</p></li>
44984+ element's <span data-x="concept-textarea/input-cursor"> text entry cursor position</span> to the
44985+ beginning of the text control, and <span data-x="set the selection direction">set its selection
44986+ direction</span> to "<code data-x="">none</code>".</p></li>
4498744987 </ol>
4498844988
4498944989 </div>
@@ -49240,8 +49240,9 @@ You cannot submit this form when the field is incorrect.</samp></pre>
4924049240
4924149241 <li><p>If the element's <span data-x="concept-fe-value">value</span> (after applying the
4924249242 <span>value sanitization algorithm</span>) is different from <var>oldValue</var>, and the
49243- element has a text entry cursor position, move the text entry cursor position to the end of the
49244- text control, unselecting any selected text and <span data-x="set the selection
49243+ element has a <span data-x="concept-textarea/input-cursor">text entry cursor position</span>,
49244+ move the <span data-x="concept-textarea/input-cursor">text entry cursor position</span> to the
49245+ end of the text control, unselecting any selected text and <span data-x="set the selection
4924549246 direction">resetting the selection direction</span> to "<code data-x="">none</code>".</p></li>
4924649247 </ol>
4924749248 </dd>
@@ -51236,9 +51237,10 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {
5123651237 true.</p></li>
5123751238
5123851239 <li><p>If the new <span data-x="concept-fe-api-value">API value</span> is different from
51239- <var>oldAPIValue</var>, then move the text entry cursor position to the end of the text control,
51240- unselecting any selected text and <span data-x="set the selection direction">resetting the
51241- selection direction</span> to "<code data-x="">none</code>".</p></li>
51240+ <var>oldAPIValue</var>, then move the <span data-x="concept-textarea/input-cursor">text entry
51241+ cursor position</span> to the end of the text control, unselecting any selected text and <span
51242+ data-x="set the selection direction">resetting the selection direction</span> to "<code
51243+ data-x="">none</code>".</p></li>
5124251244 </ol>
5124351245
5124451246 <p>The <dfn><code data-x="dom-textarea-textLength">textLength</code></dfn> IDL attribute must
@@ -54713,23 +54715,39 @@ MIT Room 32-G524
5471354715
5471454716 <div w-nodev>
5471554717
54716- <p>For <code>input</code> elements, these methods and attributes must operate on the element's
54717- <span data-x="concept-fe-value">value</span>. For <code>textarea</code> elements, these methods and
54718- attributes must operate on the element's <span data-x="concept-textarea-raw-value">raw
54719- value</span>.</p>
54718+ <p>All <code>input</code> elements to which these APIs <span
54719+ data-x="concept-input-apply">apply</span>, and all <code>textarea</code> elements, have either a
54720+ <dfn data-x="concept-textarea/input-selection">selection</dfn> or a <dfn
54721+ data-x="concept-textarea/input-cursor">text entry cursor position</dfn> at all times (even for
54722+ elements that are not <span>being rendered</span>). The initial state must consist of a <span
54723+ data-x="concept-textarea/input-cursor">text entry cursor</span> at the beginning of the control.</p>
54724+ <!-- Previously the spec said to let platform conventions decide, but the web depends on it being
54725+ at the beginning; see https://bugzilla.mozilla.org/show_bug.cgi?id=1337392 -->
54726+
54727+ <p>For <code>input</code> elements, these APIs must operate on the element's <span
54728+ data-x="concept-fe-value">value</span>. For <code>textarea</code> elements, these APIs must
54729+ operate on the element's <span data-x="concept-textarea-raw-value">raw value</span>. In the below
54730+ algorithms, we call the value string being operated on the <dfn
54731+ data-x="concept-textarea/input-relevant-value">relevant value</dfn>.</p>
5472054732
54721- <p>Where possible, user interface features for changing the text selection in <code>input</code>
54722- and <code>textarea</code> elements must be implemented in terms of the DOM API described in this
54723- section, so that, e.g., all the same events fire .</p>
54733+ <p>Characters with no visible rendering, such as U+200D ZERO WIDTH JOINER, still count as
54734+ characters. Thus, for instance, the selection can include just an invisible character, and the
54735+ text insertion cursor can be placed to one side or another of such a character .</p>
5472454736
54725- <p>The selections of <code>input</code> and <code>textarea</code> elements have a <dfn>selection
54726- direction</dfn>, which is either "<code data-x="">forward</code>", "<code
54727- data-x="">backward</code>", or "<code data-x="">none</code>". This direction is set when the user
54728- manipulates the selection. The exact meaning of the selection direction depends on the platform.
54729- To <dfn>set the selection direction</dfn> of an element to a given direction, update the element's
54730- <span>selection direction</span> to the given direction, unless the direction is "<code
54731- data-x="">none</code>" and the platform does not support that direction; in that case, update the
54732- element's <span>selection direction</span> to "<code data-x="">forward</code>".</p>
54737+ <p>Where possible, user interface features for changing the <span
54738+ data-x="concept-textarea/input-selection">text selection</span> in <code>input</code> and
54739+ <code>textarea</code> elements must be implemented using the <span>set the selection range</span>
54740+ algorithm so that, e.g., all the same events fire.</p>
54741+
54742+ <p>The <span data-x="concept-textarea/input-selection">selections</span> of <code>input</code> and
54743+ <code>textarea</code> elements have a <dfn>selection direction</dfn>, which is either "<code
54744+ data-x="">forward</code>", "<code data-x="">backward</code>", or "<code data-x="">none</code>".
54745+ This direction is set when the user manipulates the selection. The exact meaning of the selection
54746+ direction depends on the platform. To <dfn>set the selection direction</dfn> of an element to a
54747+ given direction, update the element's <span>selection direction</span> to the given direction,
54748+ unless the direction is "<code data-x="">none</code>" and the platform does not support that
54749+ direction; in that case, update the element's <span>selection direction</span> to "<code
54750+ data-x="">forward</code>".</p>
5473354751
5473454752 <div class="note">
5473554753 <p>On Windows, the direction indicates the position of the caret relative to
@@ -54773,11 +54791,16 @@ MIT Room 32-G524
5477354791 data-x="dom-textarea/input-selectionStart">selectionStart</code> <span data-x="do not apply">does
5477454792 not apply</span> to this element, return null.</p></li>
5477554793
54776- <li><p>If there is no selection, return the offset (in logical order) to the character that
54777- immediately follows the text entry cursor.</p></li>
54794+ <li><p>If there is no <span data-x="concept-textarea/input-selection">selection</span>, return
54795+ the offset (in logical order) within the <span
54796+ data-x="concept-textarea/input-relevant-value">relevant value</span> to the character that
54797+ immediately follows the <span data-x="concept-textarea/input-cursor">text entry
54798+ cursor</span>.</p></li>
5477854799
54779- <li><p>Return the offset (in logical order) to the character that immediately follows
54780- the start of the selection.</p></li>
54800+ <li><p>Return the offset (in logical order) within the <span
54801+ data-x="concept-textarea/input-relevant-value">relevant value</span> to the character that
54802+ immediately follows the start of the <span
54803+ data-x="concept-textarea/input-selection">selection</span>.</p></li>
5478154804 </ol>
5478254805
5478354806 <p>The <code data-x="dom-textarea/input-selectionStart">selectionStart</code> attribute's setter
@@ -54808,11 +54831,16 @@ MIT Room 32-G524
5480854831 data-x="dom-textarea/input-selectionEnd">selectionEnd</code> <span data-x="do not apply">does
5480954832 not apply</span> to this element, return null.</p></li>
5481054833
54811- <li><p>If there is no selection, return the offset (in logical order) to the character that
54812- immediately follows the text entry cursor.</p></li>
54834+ <li><p>If there is no <span data-x="concept-textarea/input-selection">selection</span>, return
54835+ the offset (in logical order) within the <span
54836+ data-x="concept-textarea/input-relevant-value">relevant value</span> to the character that
54837+ immediately follows the <span data-x="concept-textarea/input-cursor">text entry
54838+ cursor</span>.</p></li>
5481354839
54814- <li><p>Return the offset (in logical order) to the character that immediately follows
54815- the end of the selection.</p></li>
54840+ <li><p>Return the offset (in logical order) within the <span
54841+ data-x="concept-textarea/input-relevant-value">relevant value</span> to the character that
54842+ immediately follows the end of the <span
54843+ data-x="concept-textarea/input-selection">selection</span>.</p></li>
5481654844 </ol>
5481754845
5481854846 <p>The <code data-x="dom-textarea/input-selectionEnd">selectionEnd</code> attribute's setter must
@@ -54880,14 +54908,17 @@ MIT Room 32-G524
5488054908
5488154909 <li><p>If <var>end</var> is null, let <var>end</var> be zero.</p></li>
5488254910
54883- <li><p>Set the selection of the text control to the sequence of characters starting with the
54884- character at the <var>start</var>th position (in logical order) and ending with the character at
54885- the <span data-x="">(<var>end</var>-1)</span>th position. Arguments greater than the length of
54886- the value of the text control (including the special value infinity) must be treated as pointing
54887- at the end of the text control. If <var>end</var> is less than or equal to <var>start</var> then
54888- the start of the selection and the end of the selection must both be placed immediately before
54889- the character with offset <var>end</var>. In UAs where there is no concept of an empty selection,
54890- this must set the cursor to be just before the character with offset <var>end</var>.</p></li>
54911+ <li><p>Set the <span data-x="concept-textarea/input-selection">selection</span> of the text
54912+ control to the sequence of characters within the <span
54913+ data-x="concept-textarea/input-relevant-value">relevant value</span> starting with the character
54914+ at the <var>start</var>th position (in logical order) and ending with the character at the <span
54915+ data-x="">(<var>end</var>-1)</span>th position. Arguments greater than the length of the <span
54916+ data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control
54917+ (including the special value infinity) must be treated as pointing at the end of the text
54918+ control. If <var>end</var> is less than or equal to <var>start</var> then the start of the
54919+ selection and the end of the selection must both be placed immediately before the character with
54920+ offset <var>end</var>. In UAs where there is no concept of an empty selection, this must set the
54921+ cursor to be just before the character with offset <var>end</var>.</p></li>
5489154922
5489254923 <li><p>If <var>direction</var> is not a <span>case-sensitive</span> match for either the string
5489354924 "<code data-x="">backward</code>" or "<code data-x="">forward</code>", or if the
@@ -54897,11 +54928,13 @@ MIT Room 32-G524
5489754928 <li><p><span>Set the selection direction</span> of the text control to
5489854929 <var>direction</var>.</p></li>
5489954930
54900- <li><p>If the previous steps caused the selection of the text control to be modified (in either
54901- extent or <span data-x="selection direction">direction</span>), then <span>queue a task</span>,
54902- using the <span>user interaction task source</span>, to <span data-x="concept-event-fire">fire an
54903- event</span> named <code data-x="event-select">select</code> at the element, with the <code
54904- data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
54931+ <li><p>If the previous steps caused the <span
54932+ data-x="concept-textarea/input-selection">selection</span> of the text control to be modified (in
54933+ either extent or <span data-x="selection direction">direction</span>), then <span>queue a
54934+ task</span>, using the <span>user interaction task source</span>, to <span
54935+ data-x="concept-event-fire">fire an event</span> named <code data-x="event-select">select</code>
54936+ at the element, with the <code data-x="dom-Event-bubbles">bubbles</code> attribute initialized to
54937+ true.</p></li>
5490554938
5490654939 </ol>
5490754940
@@ -54934,24 +54967,29 @@ MIT Room 32-G524
5493454967 <li><p>If <var>start</var> is greater than <var>end</var>, then throw an
5493554968 <span>"<code>IndexSizeError</code>"</span> <code>DOMException</code>.</p></li>
5493654969
54937- <li><p>If <var>start</var> is greater than the length of the value of the text control, then set
54938- it to the length of the value of the text control.</p></li>
54970+ <li><p>If <var>start</var> is greater than the length of the <span
54971+ data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control, then
54972+ set it to the length of the <span data-x="concept-textarea/input-relevant-value">relevant
54973+ value</span> of the text control.</p></li>
5493954974
54940- <li><p>If <var>end</var> is greater than the length of the value of the text control, then set it
54941- to the length of the value of the text control.</p></li>
54975+ <li><p>If <var>end</var> is greater than the length of the <span
54976+ data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control, then
54977+ set it to the length of the <span data-x="concept-textarea/input-relevant-value">relevant
54978+ value</span> of the text control.</p></li>
5494254979
5494354980 <li><p>Let <var>selection start</var> be the current value of the <code
5494454981 data-x="dom-textarea/input-selectionStart">selectionStart</code> attribute.</p></li>
5494554982
5494654983 <li><p>Let <var>selection end</var> be the current value of the <code
5494754984 data-x="dom-textarea/input-selectionEnd">selectionEnd</code> attribute.</p></li>
5494854985
54949- <li><p>If <var>start</var> is less than <var>end</var>, delete the sequence of
54950- characters starting with the character at the <var>start</var>th position (in logical
54951- order) and ending with the character at the <span data-x="">(< var>end </var>-1)</span>th
54952- position.</p></li>
54986+ <li><p>If <var>start</var> is less than <var>end</var>, delete the sequence of characters within
54987+ the element's <span data-x="concept-textarea/input-relevant-value">relevant value</span> starting
54988+ with the character at the <var>start </var>th position (in logical order) and ending with the
54989+ character at the <span data-x="">(<var>end</var>-1)</span>th position.</p></li>
5495354990
54954- <li><p>Insert the value of the first argument into the text of the value of the text control,
54991+ <li><p>Insert the value of the first argument into the text of the <span
54992+ data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control,
5495554993 immediately before the <var>start</var>th character.</p></li>
5495654994
5495754995 <li><p>Let <var>new length</var> be the length of the value of the first argument.</p></li>
@@ -55050,22 +55088,10 @@ MIT Room 32-G524
5505055088 "<span data-x="dom-SelectionMode-preserve">preserve</span>" // default
5505155089};</pre>
5505255090
55053- <p>All elements to which this API <span data-x="concept-input-apply">applies</span> have either a
55054- selection or a text entry cursor position at all times (even for elements that are not <span>being
55055- rendered</span>). The initial state must consist of a text entry cursor at the beginning of the
55056- control.</p>
55057- <!-- Previously the spec said to let platform conventions decide, but the web depends on it being
55058- at the beginning; see https://bugzilla.mozilla.org/show_bug.cgi?id=1337392 -->
55091+ <hr>
5505955092
5506055093 </div>
5506155094
55062-
55063- <p>Characters with no visible rendering, such as U+200D ZERO WIDTH JOINER, still count as
55064- characters. Thus, for instance, the selection can include just an invisible character, and the
55065- text insertion cursor can be placed to one side or another of such a character.</p>
55066-
55067- <hr>
55068-
5506955095 <div class="example">
5507055096
5507155097 <p>To obtain the currently selected text, the following JavaScript suffices:</p>
0 commit comments