-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a StaticRange constructor #590
Comments
(As part of adding a constructor we should also expand the introduction of these objects a bit and mention the relative high cost of |
I dunno that there's any point to doing validation here. Anything working with StaticRange needs to handle invalid ones somehow anyway. Apart from that, the constructor generally makes sense to me, assuming we're doing StaticRange at all. Are we? Has anyone other than WebKit added it? Where is WebKit using it? |
Chromium has added it as well. It's used with Input Events. |
WebKit uses it in input events. |
Right, https://w3c.github.io/input-events/index.html has a method that can return them (not defined in detail though). It seems like we should restrict the boundary node from being a doctype and possibly from being an attribute as well, depending on #607. |
Hi all! I work on the Microsoft Edge team and we were interested in using static ranges as part of our Highlight API proposal. In case you’re unfamiliar with the highlight API, it provides a way for web developers to style the text inside arbitrary ranges within the DOM, which can be useful for editing applications that are trying to implement their own selection, find-on-page, spellchecking, etc. If you would like more details, please refer to this explainer: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/highlight/explainer.md. We believe the highlight API is a great use case for StaticRange; however, we would need StaticRanges to be constructible, so that authors can create these range objects and add them to one or more HighlightRangeGroups (see examples in the explainer). From reading the responses here as well as w3c/staticrange#3, it sounds like there is general agreement about giving StaticRange a constructor and we’re just trying to iron out whether we need input validation. Is that correct? If so, I was wondering if there has been any further discussion on this topic (possibly elsewhere) or if we could pick this up again? I’m also happy to help drive this forward if needed. |
There has been no further discussion that I'm aware of. I think we should restrict the types of nodes you can specify, but otherwise I don't think there's a need for validation here. Also, to be clear, happy for you to drive this. We'll need web-platform-tests, bugs against implementations, and a PR against the DOM Standard ( |
Thanks @annevk ! I’m happy to help with all of those things. I think Range and StaticRange should have the same set of allowed/disallowed nodes. From looking at the spec for Range.setStart/setEnd (https://dom.spec.whatwg.org/#concept-range-bp-set), it seems that doctype is the only disallowed one right now. So I propose we throw an exception (InvalidNodeTypeError) only if a doctype is passed to the StaticRange constructor. In the future, if we want to disallow other node types like Attr, we can make an update to disallow them on both range types. Let me know if that sounds good. cc: @BoCupp-Microsoft, @gked |
Unless there's a good case for allowing |
That's a good point actually - we wouldn't want an author to take a dependency on So are we fine with disallowing |
Sounds great, though note that I'd expect at least some quibbling over the shape of the constructor as well, but who knows. 😊 |
I've created spec and WPT test PRs for this, and also filed implementation bugs. Please take a look and let me know what you think. Spec PR: #778 Implementation bugs: |
I've uploaded a patch for WebKit on https://bugs.webkit.org/show_bug.cgi?id=201055. There is one minor bug in the WPT test but everything else looks good to me. |
The WebKit implementation has landed in https://trac.webkit.org/changeset/249079. |
Somehow
StaticRange
got added to browsers without the TAG noting the lack of a constructor. #589 addsStaticRange
to the DOM Standard.The proposal by @garykac in https://w3c.github.io/staticrange/index.html#interface-staticrange seems reasonable. You require a dictionary to be passed specifying all the bits.
One question is whether those bits should be validated as w3c/staticrange#13 suggests or whether we should allow any inputs and just pass them through. After all, you need to validate a
StaticRange
object whenever you use it, so why do it here as well? (Do we have any APIs yet that takeStaticRange
objects?)It's not entirely clear to me what the tradeoffs are here.
cc @rniwa @johanneswilm @bzbarsky @dstorey
The text was updated successfully, but these errors were encountered: