Skip to content

Comments

Fix :Ctrl+K triggers browser search#1659

Closed
saiteja-in wants to merge 1 commit intoMail-0:stagingfrom
saiteja-in:fix-bug-ctrlk
Closed

Fix :Ctrl+K triggers browser search#1659
saiteja-in wants to merge 1 commit intoMail-0:stagingfrom
saiteja-in:fix-bug-ctrlk

Conversation

@saiteja-in
Copy link

@saiteja-in saiteja-in commented Jul 7, 2025

Description

This PR resolves the issue where pressing Ctrl+K (or Cmd+K on Mac) was triggering the browser's default find-in-page dialog instead of opening the application's command palette. The fix ensures users can properly access the search and filter functionality within the mail interface.

Implementation

useEffect(() => {
  const handleKeyDown = (event: KeyboardEvent) => {
    if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
      event.preventDefault();
      setIsCommandPaletteOpen('true');
    }
  };

  document.addEventListener('keydown', handleKeyDown);
  return () => document.removeEventListener('keydown', handleKeyDown);
}, [setIsCommandPaletteOpen]);

Type of Change

Please delete options that are not relevant.

  • 🐛 Bug fix (non-breaking change which fixes an issue)

Areas Affected

Please check all that apply:

  • User Interface/Experience

Testing Done

Describe the tests you've done:

  • Manual testing performed
  • Cross-browser testing (if UI changes)

Security Considerations

For changes involving data or authentication:

  • No sensitive data is exposed
  • Authentication checks are in place
  • Input validation is implemented
  • Rate limiting is considered (if applicable)

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in complex areas
  • I have updated the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix/feature works
  • All tests pass locally
  • Any dependent changes are merged and published

Additional Notes

fix.mp4

Closes #1658

Summary by CodeRabbit

  • New Features
    • Added support for opening the command palette using the Ctrl+K (or Cmd+K on Mac) keyboard shortcut.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 7, 2025

Walkthrough

A new useEffect hook was introduced in the MailLayout component to intercept the Ctrl+K (or Cmd+K) keyboard shortcut. When this shortcut is pressed, the browser's default search is prevented and the application's command palette is opened instead.

Changes

File(s) Change Summary
apps/mail/components/mail/mail.tsx Added a useEffect to listen for Ctrl+K/Cmd+K and open the command palette, preventing browser search.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser
    participant MailLayout
    participant CommandPalette

    User->>Browser: Presses Ctrl+K/Cmd+K
    Browser->>MailLayout: Dispatches keydown event
    MailLayout->>MailLayout: useEffect intercepts event, prevents default
    MailLayout->>CommandPalette: Opens command palette (sets isCommandPaletteOpen = true)
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent browser's default search on Ctrl+K/Cmd+K and open application's command palette (#1658)
Enable users to search/filter emails using the application's interface via keyboard shortcut (#1658)

Possibly related PRs

Suggested reviewers

  • MrgSub

Poem

Ctrl and K, a magic pair,
No more browser search to bear!
The palette pops with rabbit glee,
Searching mail as quick as can be.
With every hop and every key,
CodeRabbit brings productivity!
🐇⌨️✨


📜 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 8a17b37 and 676174a.

📒 Files selected for processing (1)
  • apps/mail/components/mail/mail.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
apps/mail/components/mail/mail.tsx (1)
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
🔇 Additional comments (1)
apps/mail/components/mail/mail.tsx (1)

394-404: Excellent implementation of the Ctrl+K shortcut fix!

This useEffect hook effectively solves the browser search conflict by:

  • Intercepting the keydown event at the document level for global coverage
  • Supporting both Ctrl (Windows/Linux) and Cmd (Mac) with ctrlKey || metaKey
  • Preventing the default browser behavior with preventDefault()
  • Properly cleaning up the event listener on component unmount
  • Using the existing query state system for command palette management

The implementation is clean, follows React best practices, and integrates well with the existing hotkey infrastructure.

✨ 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

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Fixed browser shortcut conflict by preventing default Ctrl+K/Cmd+K behavior to properly trigger the app's command palette instead of browser search.

  • Added event listener in apps/mail/components/mail/mail.tsx to intercept and prevent default browser search behavior
  • Implemented proper cleanup with useEffect's return function to remove event listener
  • Used preventDefault() to stop browser's default find-in-page dialog from appearing
  • Ensured cross-browser compatibility by handling both ctrlKey and metaKey for Windows/Linux and Mac respectively

1 file reviewed, no comments
Edit PR Review Bot Settings | Greptile

@ahmetskilinc
Copy link
Contributor

Which browser was this an issue in? we havent seen any issue with it?

@saiteja-in
Copy link
Author

saiteja-in commented Jul 7, 2025

Which browser was this an issue in? we havent seen any issue with it?

Windows, Brave .haven't tried it on mac

@saiteja-in saiteja-in closed this Jul 7, 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.

Ctrl+K triggers browser search instead of application command palette

2 participants