-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: ensure consistent element selection by applying parent-child grouping #783
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
Conversation
WalkthroughRemoves a conditional check for anchor tags and always applies parent-child grouping filtering to grouped elements at point before sorting by DOM depth and selecting the first element. No exported signatures changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant CS as ClientSelectorGenerator
participant DOM as Document
User->>CS: getElementAtPoint(x, y)
CS->>DOM: query elements at (x, y)
DOM-->>CS: elementsAtPoint
CS->>CS: group elements (groupedElementsAtPoint)
note over CS: Conditional branch removed
CS->>CS: filterParentChildGroupedElements(groupedElementsAtPoint)
CS->>CS: sort by DOM depth
CS-->>User: first element from filtered, sorted list
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Pre-merge checks✅ Passed checks (3 passed)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/helpers/clientSelectorGenerator.ts (2)
960-962
: Good fix: always de‑nest to avoid child captureApplying parent/child filtering unconditionally matches the PR goal and should stop highlighting nested child nodes in list mode. Minor nit:
filteredElements
doesn’t need reassignment—useconst
.- let filteredElements = this.filterParentChildGroupedElements( + const filteredElements = this.filterParentChildGroupedElements( groupedElementsAtPoint );
981-997
: Prefer “lowest parent” candidates to reduce ambiguityCurrent filter returns all ancestors that contain any grouped child, then you sort by depth. Make the intent explicit by returning only the “lowest parents” (parents that don’t have another parent candidate above them). This shrinks the candidate set and avoids relying on sort stability.
private filterParentChildGroupedElements( groupedElements: HTMLElement[] ): HTMLElement[] { - const result: HTMLElement[] = []; - - for (const element of groupedElements) { - const hasGroupedChild = groupedElements.some( - (other) => other !== element && element.contains(other) - ); - - if (hasGroupedChild) { - result.push(element); - } - } - - return result.length > 0 ? result : groupedElements; + // First, keep only elements that contain another grouped element (i.e., parents) + const parents = groupedElements.filter(el => + groupedElements.some(other => other !== el && el.contains(other)) + ); + if (parents.length === 0) return groupedElements; + + // Then, keep only the lowest parents (no other parent in the set contains them) + const lowestParents = parents.filter(el => + !parents.some(other => other !== el && other.contains(el)) + ); + return lowestParents.length > 0 ? lowestParents : parents; }
What this PR does?
Fixes the bug wherein the list selection highlighting was capturing child elements.
Summary by CodeRabbit
Bug Fixes
Refactor