Skip to content
New issue

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

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

Already on GitHub? # to your account

Fixes https://github.com/w3c/selection-api/issues/170. #172

Merged
merged 1 commit into from
Mar 20, 2024
Merged
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
46 changes: 38 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ <h2>
in the [=document tree=]. It could be in a [=shadow tree=] of
the same [=document=].
</p>
<p>
Each <a>document</a>, <a>input</a> element, and <a>textarea</a> element has a boolean
<dfn>has scheduled selectionchange event</dfn>, which is initially false.
</p>
</section>
<section data-dfn-for="Selection">
<h2>
Expand Down Expand Up @@ -957,20 +961,46 @@ <h3>
</h3>
<p>
When the <a>selection</a> is dissociated with its <a>range</a>,
associated with a new <a>range</a> or the associated <a>range</a>'s
associated with a new <a>range</a>, or the associated <a>range</a>'s
<a>boundary point</a> is mutated either by the user or the content script,
the user agent must <a>queue a task</a> on the <a>user interaction task source</a>
to <a>fire an event</a> named <code>selectionchange</code>,
which does not bubble and is not cancelable,
at the <a>document</a> associated with the <a>selection</a>.
the user agent must <a>schedule a selectionchange event</a> on <a>document</a>.
</p>
<p>
When an [^input^] or [^textarea^] element provide a text selection
and its selection changes (in either extent or [=direction=]),
the user agent must <a>queue a task</a> on the <a>user interaction task source</a>
to <a>fire an event</a> named <code>selectionchange</code>,
which bubbles but is not cancelable, at the element.
the user agent must <a>schedule a selectionchange event</a> on the element.
</p>
<section>
<h4>Scheduling <code>selectionhange</code> event</h4>
<p>To <dfn>schedule a selectionchange event</dfn> on a node <var>target</var>, run these steps:</p>
<ol>
<li>
If <var>target</var>'s <a>has scheduled selectionchange event</a> is true,
abort these steps.
</li>
<li>
<a>Queue a task</a> on the <a>user interaction task source</a> to
Copy link
Member

Choose a reason for hiding this comment

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

Instead of queue a task, you want https://html.spec.whatwg.org/#queue-an-element-task and also pass that target. This way some aspects of the task get better initialized.

(We want to eventually remove "queue a task".)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that'll work because target can be a document, which isn't an element.

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, I guess we can invoke https://html.spec.whatwg.org/#queue-a-global-task instead and obtain the global ourselves, but it seems there should be a helper for that. Maybe the primitive should be "queue an object task" where "object" has to be a "platform object". @domenic what do you think about that?

I also wonder if someone moves an element from one document to another, should we really have the global from the former document or should we use the element's node document's global object?

<a>fire a selectionchange event</a> on <var>target</var>.
</li>
</ol>
</section>
<section>
<h4>Firing <code>selectionhange</code> event</h4>
<p>To <dfn>fire a selectionchange event</dfn> on a node <var>target</var>, run these steps:</p>
<ol>
<li>
Set <var>target</var>'s <a>has scheduled selectionchange event</a> to false.
</li>
<li>
If <var>target</var> is an element, <a>fire an event</a> named <code>selectionchange</code>,
which bubbles and not cancelable, at <var>target</var>.
</li>
<li>
Otherwise, if <var>target</var> is a document, <a>fire an event</a> named <code>selectionchange</code>,
which does not bubble and not cancelable, at <var>target</var>.
</li>
</ol>
</section>
</section>
</section>
<section id='conformance'>
Expand Down
Loading