Skip to content

Comments

fix: make clipboard work along with wrong position of popup#1493

Closed
retrogtx wants to merge 5 commits intoMail-0:stagingfrom
retrogtx:clipboard
Closed

fix: make clipboard work along with wrong position of popup#1493
retrogtx wants to merge 5 commits intoMail-0:stagingfrom
retrogtx:clipboard

Conversation

@retrogtx
Copy link
Contributor

@retrogtx retrogtx commented Jun 26, 2025

clipboard.mp4

Summary by CodeRabbit

  • New Features

    • Improved clipboard copy functionality with enhanced error handling and fallback support for copying text.
    • Centralized clipboard copy actions through a unified hook for a more consistent user experience.
  • Refactor

    • Simplified popover positioning and updated styling for text selection actions.
    • Added debounced handling for text selection to improve responsiveness.
    • Cleaned up unused code related to unsubscribe and attachment selection in the mail display.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 26, 2025

Walkthrough

This update refactors clipboard copy functionality in mail display components by introducing a centralized hook with improved error handling and fallback support. It also simplifies popover positioning and styling, removes obsolete code related to unsubscribe and attachments, and updates internal logic for copying sender emails and selected text.

Changes

File(s) Change Summary
apps/mail/components/mail/mail-display.tsx Refactored to use a new clipboard hook, simplified popover positioning/styling, cleaned up unused unsubscribe and attachment code, improved copy logic.
apps/mail/hooks/use-copy-to-clipboard.ts Refactored clipboard copy logic to add fallback, error handling, and updated function signature to allow optional ID.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MailDisplay
    participant useCopyToClipboard
    participant Toast

    User->>MailDisplay: Click "Copy" (email or text selection)
    MailDisplay->>useCopyToClipboard: copyToClipboard(value, [id])
    alt Clipboard API available
        useCopyToClipboard->>Clipboard API: writeText(value)
        Clipboard API-->>useCopyToClipboard: Success/Failure
    else Fallback
        useCopyToClipboard->>DOM: Create hidden textarea, execCommand('copy')
        DOM-->>useCopyToClipboard: Success/Failure
    end
    alt Success
        useCopyToClipboard->>Toast: Show success
    else Failure
        useCopyToClipboard->>Toast: Show error
    end
Loading

Possibly related PRs

Suggested reviewers

  • MrgSub

Poem

A bunny hopped through lines of code,
With popovers fixed and copy bestowed.
Now emails and text are easy to share,
With robust clipboard magic everywhere!
Old code is gone, the new shines bright—
Copy with joy, from morning to night.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6550416 and ec765cd.

📒 Files selected for processing (1)
  • apps/mail/components/mail/mail-display.tsx (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/mail/components/mail/mail-display.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
apps/mail/hooks/use-copy-to-clipboard.ts (1)

31-31: Improve code readability with optional chaining.

The static analysis tool correctly identifies that this can be simplified using optional chaining.

Apply this diff to use optional chaining:

-    if (navigator.clipboard && navigator.clipboard.writeText) {
+    if (navigator.clipboard?.writeText) {
apps/mail/components/mail/mail-display.tsx (2)

90-92: Simplified positioning logic improves clarity.

The changes to use center coordinates and fixed positioning are good improvements for popover placement. However, the extremely high z-index value (2147483647) suggests there might be CSS specificity conflicts that could be resolved more elegantly.

Consider investigating why such a high z-index is needed and whether the underlying CSS conflicts can be resolved at a lower level.

Also applies to: 133-139


148-151: Consider alternative approach to invisible trigger button.

The invisible button (h-0 w-0) appears to be a workaround for popover positioning. While functional, this approach is semantically unclear and could be confusing for future maintainers.

Consider whether the popover component API supports programmatic positioning without requiring a trigger element, or if a more semantic approach is possible.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 315b2fc and 3456cf0.

📒 Files selected for processing (2)
  • apps/mail/components/mail/mail-display.tsx (6 hunks)
  • apps/mail/hooks/use-copy-to-clipboard.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/mail/components/mail/mail-display.tsx (1)
apps/mail/hooks/use-copy-to-clipboard.ts (1)
  • useCopyToClipboard (4-54)
🪛 Biome (1.9.4)
apps/mail/hooks/use-copy-to-clipboard.ts

[error] 31-31: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (4)
apps/mail/hooks/use-copy-to-clipboard.ts (2)

7-24: Excellent fallback implementation for clipboard copying.

The fallback mechanism is well-implemented with proper DOM manipulation, styling to hide the textarea, and thorough cleanup. Good error handling and boolean return for success indication.


26-51: Well-designed clipboard hook with robust error handling.

The implementation properly handles the modern clipboard API with graceful fallback, provides clear user feedback through toasts, and manages state effectively. The configurable reset delay is a nice touch for customization.

apps/mail/components/mail/mail-display.tsx (2)

58-59: Good integration of the new clipboard hook.

Appropriate imports for the enhanced clipboard functionality and popover components.


184-188: Excellent integration of the centralized clipboard functionality.

The copy button properly uses the new clipboard hook and manages the selection state correctly. This is a good example of how to integrate the centralized clipboard functionality.

@retrogtx
Copy link
Contributor Author

this also has a toast btw, not in the video cause of the arrow zoom

@graphite-app
Copy link
Contributor

graphite-app bot commented Jul 4, 2025

Merge activity

  • Jul 4, 5:55 PM UTC: Graphite disabled "merge when ready" on this PR due to: Unknown error.
  • Jul 4, 5:56 PM UTC: Graphite disabled "merge when ready" on this PR due to: Unknown error.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Text Selection Popover Fails to Hide

The text selection popover remains visible after text is deselected or when no text is selected. This occurs because the handleSelectionChange function no longer clears the selectionCoords and selectedText state when window.getSelection() is collapsed or empty. The removal of the setSelectionCoords(null) and setSelectedText('') calls prevents the popover from hiding, leading to a stale UI.

apps/mail/components/mail/mail-display.tsx#L81-L85

const handleSelectionChange = useCallback(() => {
const selection = window.getSelection();
if (!selection || selection.isCollapsed) {
return;
}

Fix in CursorFix in Web


BugBot free trial expires on July 22, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@MrgSub MrgSub closed this Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants