Re: [whatwg/dom] Add definition for composed selection range (PR #1342)

@dizhang168 commented on this pull request.



>       <li>Set <var>range</var>'s
      <a for=range>start</a> to <var>bp</var>.
+
+     <li>If <var>selection range</var> is not null,
+     set <var>selection range</var>’s
+     <a for="range">start</a> to <var>bp</var>.

Yes, the fact that we have a collapsed legacy live range within a shadow DOM is a shortcoming of the existing Selection API. We are keeping it this way for backward compatibility, but hopefully the new changes will feel more natural to the users and they will depend on getComposedRanges() to get the right selection endpoints within the document.

>       to <var>bp</var>.
 
+     <li>Otherwise, if <var>bp</var> is
+     <a for="boundary point">after</a> the
+     <var>range</var>'s <a for=range>end</a>, then:
+      <ol>
+       <li>Set <var>range</var>'s <a for=range>end</a>
+       to <var>bp</var>.
+
+       <li>If <var>selection range</var> is not null,
+       set <var>selection range</var>’s
+       <a for="range">end</a> to <var>bp</var>.

Good catch, I should update this algorithm to collapse the selection range's endpoints if we are crossing documents.

I don't think we need to add a new "composed after/before" concept though. I have updated the algorithm such that the first condition checks if we are in the same tree. If bp and range's end are in different documents, it would match step 1, collapse and will not reach the "otherwise" step 2.

1. If range’s root is not equal to node’s root, then:
  1.1. Set range’s end to bp.
  1.2. If selection range is not null and range’s start node’s node document is not node’s node document, set selection range’s end to bp.
2. Otherwise, if bp is after the range’s end, then:
  2. 1Set range’s end to bp.
  2.2 If selection range is not null, set selection range’s end to bp.
3. Set range’s start to bp.
4. If selection range is not null, set selection range’s start to bp.

For the second point about how we need to be careful calling "before/after" in Selection API spec, I agree. Let's make sure we only compare "before/after" with shadow hosts if the node is in a shadow tree.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/1342#discussion_r1970693403
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/pull/1342/review/2642702610@github.com>

Received on Tuesday, 25 February 2025 23:54:34 UTC