Skip to content

Comments

Add Tab Popup Menu#41

Merged
iamEvanYT merged 6 commits intomainfrom
evan/tab-popup-menu
May 9, 2025
Merged

Add Tab Popup Menu#41
iamEvanYT merged 6 commits intomainfrom
evan/tab-popup-menu

Conversation

@iamEvanYT
Copy link
Member

@iamEvanYT iamEvanYT commented May 9, 2025

Summary by CodeRabbit

  • New Features

    • Added a context menu for browser tabs, accessible by right-clicking a tab. Menu options include copying the tab URL, toggling sleep/wake state, and closing the tab.
  • Refactor

    • Simplified the sidebar tab interface by removing support for multiple tab group modes and streamlining event handling and styling for a more consistent experience.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 9, 2025

Walkthrough

This update introduces a new IPC-driven context menu for browser tabs, accessible via right-click in the sidebar. It adds backend event handling, a preload bridge, and interface updates to support the menu, while also refactoring the sidebar tab components to remove multi-mode complexity and streamline tab rendering and event handling.

Changes

File(s) Change Summary
src/main/ipc/browser/tabs.ts Added IPC event listener for "tabs:show-context-menu" to display a context menu for a tab, including options to copy URL, toggle sleep/wake, and close the tab. Updated Electron imports.
src/preload/index.ts Added showContextMenu(tabId) method to tabsAPI, sending IPC message to show the tab context menu.
src/shared/flow/interfaces/browser/tabs.ts Added showContextMenu(tabId: number): void method to FlowTabsAPI interface.
src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx Refactored to remove multi-mode (glance/split) support, simplified SidebarTab and SidebarTabGroups components, removed front tab logic, and updated event handling for right-click context menu.

Sequence Diagram(s)

sequenceDiagram
    participant Renderer
    participant Preload
    participant Main

    Renderer->>Preload: tabsAPI.showContextMenu(tabId)
    Preload->>Main: ipcRenderer.send("tabs:show-context-menu", tabId)
    Main->>Main: Handle "tabs:show-context-menu" event
    Main->>Main: Retrieve tab and window
    Main->>Main: Build context menu (Copy URL, Sleep/Wake, Close)
    Main->>Main: Show context menu anchored to tab window
Loading

Possibly related PRs

  • Add Sleep Tabs Functionality #23: Implements the core tab sleep/wake functionality, including the asleep property and methods used by the new context menu to toggle tab state.

Poem

A right-click hop, a menu appears,
With options for tabs, to bring bunny cheers!
Copy the link, put to sleep, or awake—
Close with a click, for good measure’s sake.
Sidebar’s now simpler, with less to confuse,
This rabbit’s delighted by streamlined tab views!
🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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: 2

🧹 Nitpick comments (3)
src/main/ipc/browser/tabs.ts (1)

232-276: Minor readability & maintenance improvement

The context-menu items are built imperatively. Using Menu.buildFromTemplate keeps the code shorter, declarative, and easier to reorder/extend:

-const contextMenu = new Menu();
-
-contextMenu.append(new MenuItem({ /* Copy URL */ }));
-
-contextMenu.append(new MenuItem({ /* separator */ }));
-
-contextMenu.append(new MenuItem({ /* Sleep / Wake */ }));
-
-contextMenu.append(new MenuItem({ /* Close */ }));
-
-contextMenu.popup({ window: tabbedWindow.window });
+const contextMenu = Menu.buildFromTemplate([
+  {
+    label: "Copy URL",
+    enabled: hasURL,
+    click: () => hasURL && clipboard.writeText(tab.url!)
+  },
+  { type: "separator" },
+  {
+    label: isTabVisible
+      ? "Cannot put active tab to sleep"
+      : tab.asleep
+      ? "Wake Tab"
+      : "Put Tab to Sleep",
+    enabled: !isTabVisible,
+    click: () => {
+      tab.asleep ? (tab.wakeUp(), tabManager.setActiveTab(tab)) : tab.putToSleep();
+    }
+  },
+  {
+    label: "Close Tab",
+    click: () => tab.destroy()
+  }
+]);
+
+contextMenu.popup({ window: tabbedWindow.window });

No functional change – only easier to scan and less error-prone when items are added later.

src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx (2)

44-49: Guard against accidental right/middle clicks triggering “pressed” state

setIsPressed(true) runs for every mouse button, but the visual “pressed” effect is probably only intended for the primary button.
Add an early return for buttons !== 0 and !== 1, or move the state update inside the left-button branch:

 if (e.button === 0) {
   handleClick();
+  setIsPressed(true);
 }
 // Middle mouse button
 if (e.button === 1) {
   handleCloseTab(e);
+  setIsPressed(true);
 }
-
-setIsPressed(true);

This prevents the pill-shrink animation from flashing when the user right-clicks to open the context menu.


64-77: Clean-up listener on dependency change

The useEffect hook installs a global mouseup listener but only removes it on unmount.
If SidebarTab ever re-mounts (e.g., key prop changes) the previous listener remains, leading to multiple handlers.

Simplest safeguard – declare the effect with no dependencies so it only runs once:

-useEffect(() => {
+useEffect(() => {-}, []);
+}, []); // empty deps – run once

If the component really must update the listener, ensure you remove the old listener before adding a new one.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fe875ce and ffd2ba9.

📒 Files selected for processing (4)
  • src/main/ipc/browser/tabs.ts (2 hunks)
  • src/preload/index.ts (1 hunks)
  • src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx (4 hunks)
  • src/shared/flow/interfaces/browser/tabs.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/ipc/browser/tabs.ts (1)
src/main/index.ts (1)
  • browser (13-13)

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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ffd2ba9 and da3e61a.

📒 Files selected for processing (2)
  • src/preload/index.ts (1 hunks)
  • src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/preload/index.ts
🔇 Additional comments (7)
src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx (7)

12-12: Function signature simplified appropriately.

The removal of the mode and frontTab props simplifies the component interface, making it more focused and easier to maintain. This aligns well with the removal of multi-mode support described in the summary.


44-48: Good refinement of mouse button handling.

Clearly distinguishing left-click behavior with explicit comments and conditionals improves code readability and maintainability. This change ensures tab switching only happens on left mouse button clicks.


64-67: Context menu implementation looks good.

The context menu handler correctly prevents the default browser context menu and integrates with the new IPC-based showContextMenu API.


69-77: Proper event listener cleanup.

Adding a global mouseup event listener with proper cleanup in the useEffect hook is a good practice to ensure the isPressed state is reset correctly even when the mouse is released outside the component.


83-90: Styling logic significantly simplified.

The conditional styling based solely on focus state rather than multiple modes makes the code more maintainable and easier to understand.


107-157: UI structure well-organized with clear section comments.

The simplified rendering logic with clear section comments ("Left side", "Right side") improves code readability. The removal of mode-dependent rendering makes the component more maintainable.


178-182: Tab rendering simplified appropriately.

The tab rendering logic has been streamlined by removing mode-dependent styling and rendering, which aligns with the overall goal of simplifying the sidebar tab components.

@iamEvanYT iamEvanYT merged commit 73add9d into main May 9, 2025
1 check passed
@iamEvanYT iamEvanYT deleted the evan/tab-popup-menu branch May 9, 2025 17:14
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.

1 participant