fix: variable popover no longer opens on range selection in email editor#422
fix: variable popover no longer opens on range selection in email editor#422tejassinghbhati wants to merge 1 commit into
Conversation
|
@tejassinghbhati is attempting to deploy a commit to the kmkoushik's projects Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughUpdated the variable node popover to open only when the editor has a 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
The popover was bound to tiptap's `selected` NodeView prop, which is set whenever the node falls inside any selection range. Drag-selecting text containing variables opened the fallback input on every variable chip in the range, blocking copy in and out of the editor. Track the popover state from the editor's selectionUpdate event instead, and open it only when the selection is a NodeSelection pointing at this node (a direct click on the chip). Fixes usesend#277
e21d5c4 to
549ed09
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/email-editor/src/nodes/variable.tsx`:
- Line 210: Add an onOpenChange handler to the controlled Popover in the
variable node so Radix close events update the same state used by popoverOpen.
Ensure Escape and clicks outside the editor set popoverOpen to false while
preserving the existing selectionUpdate behavior for editor-internal clicks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aea17f52-cb96-412c-b587-e86f49f28117
📒 Files selected for processing (1)
packages/email-editor/src/nodes/variable.tsx
| data-drag-handle="" | ||
| > | ||
| <Popover open={props.selected}> | ||
| <Popover open={popoverOpen}> |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Add onOpenChange to handle Escape and click-outside-editor close.
The Popover is now controlled by popoverOpen but lacks an onOpenChange handler. Radix fires onOpenChange(false) on Escape and external clicks; without a handler, the popover stays open in those cases. The selectionUpdate listener covers clicks inside the editor, but Escape and clicks outside the editor are unhandled.
🔧 Suggested fix
- <Popover open={popoverOpen}>
+ <Popover open={popoverOpen} onOpenChange={setPopoverOpen}>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <Popover open={popoverOpen}> | |
| <Popover open={popoverOpen} onOpenChange={setPopoverOpen}> |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/email-editor/src/nodes/variable.tsx` at line 210, Add an
onOpenChange handler to the controlled Popover in the variable node so Radix
close events update the same state used by popoverOpen. Ensure Escape and clicks
outside the editor set popoverOpen to false while preserving the existing
selectionUpdate behavior for editor-internal clicks.
Closes #277
Problem
Selecting text in the email editor that contains variable chips popped open the fallback-value input on every variable in the selection, making it impossible to cleanly select and copy content in or out of the editor (see the screen recording in the issue).
Root cause: the popover was bound directly to tiptap's
selectedNodeView prop (<Popover open={props.selected}>). tiptap setsselectedwhenever the node is covered by any selection range, including drag and keyboard range selections, not just direct clicks on the node.Fix
Track popover visibility in component state driven by the editor's
selectionUpdateevent, and open it only when the current selection is aNodeSelectionwhose position matches this node, i.e. the user actually clicked the variable chip.ProseMirror-selectednodehighlight when inside a range selection (still usesprops.selected), so visual selection feedback is unchanged.selectionUpdate(rather than a render-time check) also covers the edge where tiptap skips re-rendering becauseselecteddidn't change, e.g. extending a node selection into a range selection with shift+arrows.Changes
packages/email-editor/src/nodes/variable.tsx: popover state fromselectionUpdate+NodeSelectioncheck; removed a strayconsole.logVerification
tsc --noEmitonpackages/email-editorpasses{{variables}}, no popovers appear and copy/paste works; click a chip and the fallback popover opens as beforeSummary by CodeRabbit
Summary