Skip selection offsets when an entire node is selected - #46889
Merged
Conversation
Signed-off-by: Simon Sapin <simon@igalia.com>
SimonSapin
requested review from
Loirooriol,
gterzian and
mrobinson
as code owners
July 30, 2026 10:53
|
🔨 Triggering try run (#30536469204) for Linux (WPT) |
|
Test results for linux-wpt from try job (#30536469204): Flaky unexpected result (42)
Stable unexpected results that are known to be intermittent (20)
|
|
✨ Try run (#30536469204) succeeded. |
mrobinson
approved these changes
Jul 30, 2026
mrobinson
left a comment
Member
There was a problem hiding this comment.
Looks good to me with a few nits:
| }); | ||
| let first_letter_selection_range = document_selection.and_then(|document_selection| { | ||
| intersect_ranges(document_selection, (*first_letter_range_u32).clone().into()) | ||
| .map(|range| range.map(|x| x - first_letter_range_u32.start)) |
Member
There was a problem hiding this comment.
Suggested change
| .map(|range| range.map(|x| x - first_letter_range_u32.start)) | |
| .map(|range| range.map(|offset| offset - first_letter_range_u32.start)) |
| // `max()..min()` producing a "backwards" range means the intersection is empty | ||
| None | ||
| } | ||
| }; |
Member
There was a problem hiding this comment.
Let's move this to a method on RangeAny if possible.
Comment on lines
+477
to
+482
| let start = if let Some(start) = document_selection.start { | ||
| self.offset_map.map(start) | ||
| } else { | ||
| // Range unbounded at the start: the concrete start is offset zero | ||
| Utf32CodeUnits(0) | ||
| }; |
Member
There was a problem hiding this comment.
Does this read a little better here and below?
Suggested change
| let start = if let Some(start) = document_selection.start { | |
| self.offset_map.map(start) | |
| } else { | |
| // Range unbounded at the start: the concrete start is offset zero | |
| Utf32CodeUnits(0) | |
| }; | |
| // Range unbounded at the start: the concrete start is offset zero | |
| let start = document_selection | |
| .start | |
| .map(|offset| self.offset_map.map(offset)) | |
| .unwrap_or(Utf32CodeUnits(0)); |
Signed-off-by: Simon Sapin <simon@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
SimonSapin
enabled auto-merge
July 30, 2026 19:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When many DOM nodes are part of the selection many of them are known to be entirely selected and computing any offset is not needed. Instead of always carrying a range (start/end pair) of offsets, this PR introduces a new
RangeAnytype where both bounds are optional, with a missing bound meaning unbounded on that side. For nodes that are entirely selected, the selection range is unbounded on both sides and no offset computation is needed. The computation skipped includes converting between UTF-8/UTF-16/UTF-32 offsets, and lookups inOffsetMapto compensate for whitespace collapsing andtext-transform.Testing: expecting no behavior change and no change in WPT test results