Re: [w3c/editing] Firefox: event.getTargetRanges() in beforeinput not consistent with window.getSelection() (Issue #493)

masayuki-nakano left a comment (w3c/editing#493)

I don't think this is a bug of Firefox unless it outputs different range than actually deleted later.

If they should always be same as `Selection`, why does `getTargetRanges()` is required for `beforeinput`? The answer should be that the range should be extended to the range where actually deleted soon. So, they can be different.

```js
  console.log(event.getTargetRanges()[0].startContainer); // returns the div
  console.log(window.getSelection().anchorNode); // returns the "Hello world" text node
```
I think you wrote opposite result. Firefox selects all things of the editing host and `getTargetReanges()` return shrunken range to leaves if there are.

In this case, ideally, the range should be select the `Text`, i.e., the containers should be `<div>` like the selection range since the `Text` itself will be deleted and replaced with a `<br>`. However, [Firefox currently shrinks the range to the leaves as far as possible](https://searchfox.org/firefox-main/rev/54da8f6bfead7871ca89f2cb18323af5f00d9620/editor/libeditor/WSRunScanner.cpp#926-932,960-967) for making the result consistent between the edge cases when the selection range boundaries are at inline element boundaries because climbing up the tree from leaf edges to unnecessary containers is easier than the opposite for web developers.

So, if this should be changed in Firefox side, the behavior should be defined/standardized more. The current definition is too rough. See also:
* https://github.com/w3c/input-events/issues/146
* https://github.com/w3c/input-events/issues/158
* https://github.com/w3c/input-events/issues/159

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/editing/issues/493#issuecomment-3644413449
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/editing/issues/493/3644413449@github.com>

Received on Friday, 12 December 2025 00:43:51 UTC