Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting cursor position in send keys #1686

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix setting cursor position in send keys
I believe the expected behaviour is:
* If the target already has focus, do nothing
* Otherwise, if the target is focusable, set the selection to the last
editable point in the element.

Previously the spec was unconditionally focusing the target
element (execpting some cases with file uploads), and therefore the
letter of the spec was to never move the caret.

This change updates it to only focus the target if it's not already
the active element, and then move the caret to the end.
  • Loading branch information
jgraham committed Sep 24, 2022
commit 8857c921f270e515f4d39e0b22c00be45b8bf668
52 changes: 41 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6220,16 +6220,17 @@ <h4><dfn>Element Send Keys</dfn></h4>

<li><p>If <var>element</var> is not <a>keyboard-interactable</a>,
return <a>error</a> with <a>error code</a> <a>element not interactable</a>.

<li><p>If <var>element</var> is not the <a>active element</a> run
the <a>focusing steps</a> for the <var>element</var>.
</ol>

<li><p>Run the substeps of the first matching condition:
<dl class="switch">
<dt><var>file</var> is true
<dd>
<ol>
<li><p>If the <a>current session</a>’s <a>strict file interactability</a> is true,
and <var>element</var> is not the <a>active element</a> run the <a>focusing
steps</a> for <var>element</var>.

<li><p>Let <var>files</var> be the result of splitting <var>text</var>
on the newline (<code>\n</code>) character.

Expand Down Expand Up @@ -6275,6 +6276,9 @@ <h4><dfn>Element Send Keys</dfn></h4>
an <a>error</a> with <a>error code</a> <a>element not
interactable</a>.

<li><p>If <var>element</var> is not the <a>active element</a> run the
<a>focusing steps</a> for <var>element</var>.

<li><p><a>Set a property</a> <code>value</code> to <var>text</var>
on <var>element</var>.

Expand All @@ -6287,18 +6291,37 @@ <h4><dfn>Element Send Keys</dfn></h4>
</dd>

<dt><var><a>element</a></var> is <a>content editable</a>
<dd>If <var><a>element</a></var> does not currently have focus,
set the text insertion caret after any child content.
<dd>
<ol>
<li><p>If <var>element</var> is not the <a>active element</a>:
<ol>
<li><p>Run the <a>focusing steps</a> for <var>element</var>.

<li><p>Let <var>child count</var> be the [=map/size=]
of <var>element</var>'s [=tree/children=].

<li><p>Let <var>range</var> be a <a>live range</a> with [=range/start=]
and [=range/end=] (<var>element</var>, <var>child count</var>).

<li><p>Set the <a>active document</a>'s <a>selection</a>
to <var>range</var>.
Comment on lines +6306 to +6307
Copy link
Contributor

@sadym-chromium sadym-chromium Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this means to select the whole element's content, or put just to put selection to the very end?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to be a collapsed range, whose start and end node is element and whose offset is child count i.e. a zero-length selection corresponding to a caret position at the end of the element.

</ol>
</ol>
</dd>
<dt>Otherwise
<dd>
<ol>
<li><p>If <var>element</var> does not currently have focus,
let <var>current text length</var> be the
[=string/length=] of <var><a>element</a></var>’s <a>API value</a>.
<li><p>If <var>element</var> is not the <a>active element</a>:
<ol>
<li><p>Let <var>current text length</var> be the
[=string/length=] of <var><a>element</a></var>’s <a>API value</a>.

<li><p>Set the text insertion caret using <a>set selection range</a>
using <var>current text length</var> for both the <code>start</code>
and <code>end</code> parameters.
<li><p>Run the <a>focusing steps</a> for <var>element</var>.

<li><p>Set the text insertion caret using <a>set selection range</a>
using <var>current text length</var> for both the <code>start</code>
and <code>end</code> parameters.
</ol>
</ol>
</dd>
</dl>
Expand Down Expand Up @@ -11156,6 +11179,13 @@ <h2>Index</h2>
<!-- visibility visible --> <li><dfn data-lt="visibility visible"><a href="https://www.w3.org/TR/page-visibility/#dom-visibilitystate-visible">Visibility state <code>visible</code></a></dfn>
</ul>

<dd><p>The following attributes are defined
in the Selection API specification: [[SELECTION-API]]
<ul>
<!-- selection --> <li><dfn data-lt=selection><a href=https://w3c.github.io/selection-api/#dfn-selection>selection</a></dfn>
</ul>


<dt>Selenium
<dd>The following functions are defined within
the <a href=https://selenium.dev>Selenium</a> project, at
Expand Down