Skip to content

Commit

Permalink
Fixes #170.
Browse files Browse the repository at this point in the history
Add a boolean flag "has scheduled selectionchange event" to document,
input element, and textarea element, and check it before queuing a task
to fire a selectionchange event.
  • Loading branch information
rniwa committed Mar 20, 2024
1 parent c44e3e1 commit 4397d66
Showing 1 changed file with 38 additions and 8 deletions.
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
<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

3 comments on commit 4397d66

@smaug----
Copy link

Choose a reason for hiding this comment

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

A bit surprising to land this kind of change without much discussion. This is technically not backwards compatible (since this changes how many events are fired).

@rniwa
Copy link
Contributor Author

@rniwa rniwa commented on 4397d66 May 22, 2024

Choose a reason for hiding this comment

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

This was discussed in #170?

@smaug----
Copy link

Choose a reason for hiding this comment

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

I can't see the web compat issue being discussed there. There was the proposal and then that just landed.

Please sign in to comment.