Skip to content

Firefox: event.getTargetRanges() in beforeinput not consistent with window.getSelection() #493

@michael

Description

@michael

Assuming you have this markup:

<div contenteditable="true">Hello world</div>

Now select the whole "Hello world" by triple clicking or pressing CTRL+A.

Now watch the onbeforeinput handler, when typing a character or hitting backspace.

function onbeforeinput(event) {
  // I'd expect the two logs below to show the same element
  // On Chrome/Safari they do, but not in Firefox
  console.log(event.getTargetRanges()[0].startContainer); // returns the div
  console.log(window.getSelection().anchorNode); // returns the "Hello world" text node
}

Repro: https://w3c.github.io/editing/repros/493.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions