Skip to content

Selection should detach associated Range when Range move to another root. #79

Open

Description

@yosinch

Current Selection API should specify behavior when associate Range, added by Selection#addRange(), when it is moved to another document or it is moved DocumentFragment.

As of February 2017, Both Edge and Firefox keep such Range to associated. They returns node in another document by Selection#anchorNode and focusNode properties.

I propose when associated Range is moved another root, Selection should stop to associate it.

Activity

  1. rniwa commented on Feb 13, 2017

    @rniwa
    Contributor

    I don't think changing the behavior of Selection-Range relationship like that only in the case where a Range's boundary points is in another document or otherwise disconnected is a good idea. This makes the API's behavior rather hard to predict.

    We should either spec Gecko/Edge's behavior or what WebKit does, which is that addRange doesn't let the original range control selection, and getRangeAt makes a new Range each time it gets called.

  2. tkent-google commented on Feb 15, 2017

    @tkent-google

    In the last draft, collapse() extend() setBaseAndExtent() and selectAllChildren() reject nodes in a different root though addRange() accepts anything. It's inconsistent. IMO, addRange() should reject Ranges with nodes in different roots.

    The Background section of the draft says:

    IE9 and Firefox 6.0a2 allow arbitrary ranges in the selection, which follows what this spec originally said. However, this leads to unpleasant corner cases that authors, implementers, and spec writers all have to deal with, and they don't make any real sense.

  3. tkent-google commented on Feb 17, 2017

    @tkent-google

    addRange() accepts anything.

    I was wrong. addRange() in the draft rejects Ranges in different root.

    https://www.w3.org/TR/selection-api/#dom-selection-addrange

    ... set ... if the root ([DOM4]) of the range's boundary points are the document associated with context object.

  4. rniwa commented on Jul 13, 2022

    @rniwa
    Contributor

    Looks like Blink implemented this proposed behavior so that when range's roots are moved to another document, it disassociates itself from the selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions