w3c / selection-api

Selection API
http://w3c.github.io/selection-api/
Other
47 stars 29 forks source link

`selectionchange` fires differently across the browser engines #332

Closed mozesstumpf closed 3 months ago

mozesstumpf commented 3 months ago

During a code execution, the Selection API's boundary-points can change multiple times. For example:

const sel = getSelection();
...
sel.removeAllRanges();
sel.addRange(range1);
...
sel.removeAllRanges();
sel.addRange(range2)

The spec does not specify how many times the selectionchange event should fire if we change the selection multiple times before the macrotask queue gets executed.

Demo to reproduce: https://codepen.io/IDontHaveAny/pen/OJemybj

In Chromium and WebKit, the selectionchange fires multiple times, even though the Selecion will be the same by the time it gets executed. In Gecko, it fires once.

rniwa commented 3 months ago

Isn't this a duplicate of https://github.com/w3c/selection-api/issues/170?

mozesstumpf commented 3 months ago

Isn't this a duplicate of #170?

It is, I close it as a duplicate