-
Notifications
You must be signed in to change notification settings - Fork 31
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
Clarify association between a selection and its range #2
Comments
Current spec states: Concerns. |
Yeah, I think we need to change the internal model of selection to be some kind of composed range from which |
Hi @rniwa! With the currently specced getComposedRanges(), I believe this issue is a blocker and should be resolved. The spec is being vague about the type of Range is associated to the Selection. In Blink (and likely all browsers), this is a Live Range and responds to DOM Mutations accordingly. However, as pointed above, if we want to support composed range, we cannot have it as a live range. I propose we clarify the above definition to: "Once a selection is associated with a given live range range, it must continue to be associated with that same range until this specification requires otherwise." But also add new definitions in Selection:
Which should default to focus/anchor, but can be set when selection crosses shadow trees. And these are the endpoints we use to compute getComposedRanges. |
Like we discussed during TPAC, we likely need to introduce the concept of live "composed" range to DOM spec and use that concept here. |
Sorry, I know we decided to introduce the concept of "live composed range", but the spec changes needed is still unclear to me. Currently, the DOM definition:
Should we change to either: Further, currently the range associated to (This is why I am thinking adding the internal concept of composed anchor/focus would be sufficient and easier. I am happy to add the concept of live composed range if there is a good way to implement it.) |
I don't think we need any new IDL at this stage. A live composed range is an internal concept, though it would require many of the things that a live range has, just none of the public API. But we would have to update it after tree mutations, for instance. A live composed range also has a pointer to a A The live range from Having said that, what is an internal concept of composed anchor/focus? |
Thanks for the explanation, very helpful. Here is my thought process. Right now, the spec says we have:
If we introduce the concept of a live composed range, then the mapping would be:
What I am proposing instead is to not add/change Range definitions: ranges are not composed. Instead, we add a new concept of a Composed Selection. The composed selection internally stores anchor and focus endpoints to be across the document. It has no direct pointer to any range.
I think this approach might be easier on the specifications, while still giving the user agents enough leeway on how they want to implement it. |
But the live range and the selection are out-of-sync if the selection is across a node tree boundary, right? And the selection offsets would similarly be out-of-sync with the composed selection offsets. So you would also have to possibly update the selection when a node tree is mutated and the live range associated with the selection is not impacted. Just as you would for a live composed range. I don't really see how this concept of a composed selection (where you still need to support the normal selection as well as you cannot directly reveal the existence of the shadow tree) is fundamentally different from a live composed range. It seems to me you have the same state to maintain and the same algorithms need to be updating that state. I guess the main difference is that these internal offsets live directly on the selection and that node tree mutations now have to know directly about a selection. Not entirely sure that that's a win. |
I see. My original proposal was to avoid having to modify Range and have everything selection scoped within the Selection. I have given it more thoughts and I am good with using a composed live range instead of introducing a new composed selection concept. The user facing changes will be the same and the implementation can be left to the user agent. Bonus, the specification should be easier because we utilize the existing Range (live range) definitions. To simplify, I propose the new structure would be:
From a standard point of view, the main changes needed would be: In DOM spec
In the Selection API spec
Note: Edit 11/12: Updated the above proposal to be clearer on how the associated range and the associated composed range interact with each other and more details on Selection API changes. |
So in the case where your selection starts outside the shadow host and goes inside of it, the API acts as-if nothing is selected? That doesn't seem good. |
Not sure why that would result in nothing getting selected, but we can move the mutation conversation to issue #168. |
Added some slides here to explain a potential proposal I would like to discuss. |
Editing WG Nov 14, 2024 IRC notes: Resolved to go with option 108:05 #2 where option 1 is: and option 2 is: @annevk @sanketj @smaug---- for reference |
I don't understand how this is an implementation detail. Typically we don't have to define implementation details. This we have to define however as it's very much observable. I'm also not sure how the composed range can be computed on the fly. I also don't really understand the slides unfortunately. They suggest that Similarly the steps under what |
The slides were written quickly and don't have all the implementation details. Apologies and I will work on a spec PR soon that does include everything. The composed range is not computed on the fly. It is tracked by the selection. Overall, my proposal is as follow: In Selection API, we change the wording to say: And in the DOM spec, we define what a composed range is: A composed range can be associated with a live range.
I see your point. We can remove that implementation detail and leave it to the user agent. We can just say return the live range associated with the this's composed range.
First, it updates the composed range. Then, it updates the live range associated to this composed range. |
Thanks. And to be clear, the composed range is live as well right? That's why we called it "live composed range" at TPAC, iirc. |
It should definitely react to mutation. However, a live range is defined as "Objects implementing the Range interface are known as live ranges." and I don't think we want to expose any of the Range interface on this composed live range. So we might need to define this differently. |
I agree with all of that, but I still think "live composed range" is the correct name given that it very much behaves in many of the same ways as a live range, it's just not script-exposed, doesn't support the same API, and can cross the shadow boundary. |
(Sorry for taking a while to get back to this) If so, I suggest we redefine what a Live Range means. It isn't only if it implements the Range interface, but is for any object that implements the AbstractRange interface and that listens to DOM mutations. Given this new definition, we can say a "Composed Live Range" is a live range. I have updated my explainer with what this would look like in spec land: |
"Once a selection is associated with a given range, it must continue to be associated with that same range until this specification requires otherwise."
This paragraph above is vague. It needs to be replaced by detailed conformance requirements saying exactly what to do for particular keystrokes, like we have for backspace/delete/etc.
The text was updated successfully, but these errors were encountered: