-
Notifications
You must be signed in to change notification settings - Fork 838
Add support for custom Selection Tools in right-click context menu #885
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: PeterDaveHello <[email protected]>
Co-authored-by: PeterDaveHello <[email protected]>
@copilot, address the feedback. |
I notice all the feedback comments are about reasoning model implementations (OpenAI API changes, model detection regex patterns, etc.) in files like Could you clarify which specific feedback relates to the selection tools changes I made? The reasoning model code referenced in the comments doesn't exist in the current codebase, so I believe there may be a mismatch between the feedback and my actual PR changes for issue #778. |
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.
@copilot, please address the feedback.
Co-authored-by: PeterDaveHello <[email protected]>
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughImplements custom Selection Tools in the right‑click context menu: background builds menu from userConfig (active defaults and custom), click handling supports custom_ IDs and sends CREATE_CHAT. Content script resolves prompts for custom tools and renders FloatingToolbar. Popup updates config asynchronously and triggers REFRESH_MENU to rebuild the context menu. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Browser as Browser Context Menu
participant BG as Background (menus.mjs)
participant Tab as Active Tab
participant CS as Content Script (index.jsx)
participant UI as FloatingToolbar
User->>Browser: Right-click selection
Browser->>BG: onShown → build menu
Note over BG: Load userConfig once<br/>- If hideContextMenu: return<br/>- Add active defaults<br/>- Add active custom tools (custom_{i})
User->>Browser: Click menu item (e.g., custom_2)
Browser->>BG: onClicked(itemId, tabId)
alt itemId startsWith "custom_"
BG->>Tab: sendMessage CREATE_CHAT { itemId, selection }
else default handling
BG->>Tab: sendMessage CREATE_CHAT { itemId, selection }
end
Tab->>CS: onMessage CREATE_CHAT
CS->>CS: getUserConfig()
alt custom_{i} valid & active with name
CS->>CS: prompt = customSelectionTools[i].prompt.replace('{{selection}}', selection)
else if toolsConfig/menuConfig match
CS->>CS: prompt from config (language cropping if applicable)
else
CS->>CS: no-op/continue existing flow
end
CS->>UI: Render FloatingToolbar { prompt, selection, session config }
sequenceDiagram
autonumber
actor User
participant Popup as Popup (SelectionTools.jsx)
participant Ext as Browser.runtime
participant BG as Background (menus.mjs)
User->>Popup: Add/Edit/Toggle/Delete selection tool
Popup->>Popup: await updateConfig({...})
Popup->>Ext: sendMessage { type: REFRESH_MENU }
Ext->>BG: REFRESH_MENU
BG->>BG: refreshMenu() with latest userConfig
Note over BG: Rebuild menu incl. active custom tools
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Assessment against linked issues
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Codex Review: Didn't find any major issues. What shall we delve into next? About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback". |
@copilot, address all the feedback. |
I've reviewed the code and both linting ( |
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.
@copilot, address all the feedback.
src/background/menus.mjs
Outdated
for (let i = 0; i < userConfig.customSelectionTools.length; i++) { | ||
const tool = userConfig.customSelectionTools[i] | ||
if (tool.active && tool.name) { | ||
Browser.contextMenus.create({ | ||
id: menuId + 'custom_' + i, | ||
parentId: menuId, | ||
title: tool.name, | ||
contexts: ['selection'], | ||
}) |
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.
@copilot, address this feedback.
src/content-script/index.jsx
Outdated
if ( | ||
!isNaN(customIndex) && | ||
customIndex >= 0 && | ||
userConfig.customSelectionTools && | ||
customIndex < userConfig.customSelectionTools.length | ||
) { | ||
const customTool = userConfig.customSelectionTools[customIndex] |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Co-authored-by: PeterDaveHello <[email protected]>
All feedback has been addressed. I've modernized the code patterns to use |
Persistent suggestions updated to latest commit ee84477 |
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.
@copilot, address ALL the feedback in the comments and reviews from CodeRabbit, Qoro Merge, and Copilot.
src/content-script/index.jsx
Outdated
const customTool = userConfig.customSelectionTools?.[customIndex] | ||
if (customTool?.active && customTool?.name) { | ||
prompt = customTool.prompt.replace('{{selection}}', data.selectionText) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
…tMenu helper and add parseInt validation Co-authored-by: PeterDaveHello <[email protected]>
I've addressed the feedback by:
All changes maintain existing functionality while following better coding practices. Build and lint validation passes. (7a86413) |
@codex review |
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.
Pull Request Overview
This PR adds support for custom selection tools in the browser extension's right-click context menu, enabling users to define their own text processing prompts that appear alongside the built-in selection tools. The implementation includes real-time menu updates when settings change and proper error handling.
Key changes:
- Added custom selection tool handling to the context menu system
- Implemented real-time menu refresh functionality triggered by settings changes
- Enhanced validation and error handling for custom tool processing
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/background/menus.mjs |
Enhanced context menu builder to include active custom tools and filter default tools based on user preferences |
src/content-script/index.jsx |
Added message handling for custom selection tools with proper validation and prompt substitution |
src/popup/sections/SelectionTools.jsx |
Added real-time menu refresh functionality and converted event handlers to async with error handling |
// Helper function to refresh context menu | ||
const refreshContextMenu = () => { | ||
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
The refreshContextMenu
function should include error handling. If the message fails to send, it will cause an unhandled promise rejection. Add .catch(console.error)
to the sendMessage
call.
// Helper function to refresh context menu | |
const refreshContextMenu = () => { | |
Browser.runtime.sendMessage({ | |
type: 'REFRESH_MENU', | |
}) | |
}).catch(console.error) |
Copilot uses AI. Check for mistakes.
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.
@copilot, address this feedback.
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.
I see the reference to lines 21-25 where the refreshContextMenu
helper function is defined. Could you provide specific feedback on what needs to be improved? The current implementation follows the established pattern for sending runtime messages in the codebase. If there are specific concerns about the implementation, I'm happy to address them.
if (!isNaN(customIndex) && customIndex >= 0) { | ||
const customTool = userConfig.customSelectionTools?.[customIndex] | ||
if (customTool?.active && customTool?.name) { |
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.
The code assumes customTool.prompt
exists but doesn't validate it. If customTool.prompt
is undefined or null, the .replace()
call will throw an error. Add a check for customTool.prompt
before calling .replace()
.
if (!isNaN(customIndex) && customIndex >= 0) { | |
const customTool = userConfig.customSelectionTools?.[customIndex] | |
if (customTool?.active && customTool?.name) { | |
if (customTool?.active && customTool?.name && typeof customTool.prompt === 'string') { |
Copilot uses AI. Check for mistakes.
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.
@copilot, address this feedback.
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.
I see the reference to lines 294-296 with the parseInt validation for custom selection tools. Could you provide specific feedback on what needs to be improved? The current implementation includes proper NaN checking, bounds validation, and optional chaining for safe array access. If there are specific concerns, please let me know what changes are needed.
Persistent suggestions updated to latest commit 7a86413 |
Codex Review: Didn't find any major issues. Bravo. About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback". |
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.
@copilot, address all the feedback.
// Helper function to refresh context menu | ||
const refreshContextMenu = () => { | ||
Browser.runtime.sendMessage({ | ||
type: 'REFRESH_MENU', | ||
}) |
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.
@copilot, address this feedback.
if (!isNaN(customIndex) && customIndex >= 0) { | ||
const customTool = userConfig.customSelectionTools?.[customIndex] | ||
if (customTool?.active && customTool?.name) { |
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.
@copilot, address this feedback.
I've reviewed the code and all linting and building passes successfully. The comment threads reference specific lines but don't contain detailed feedback to address. Could you provide more specifics about what issues need to be resolved? The current implementation follows established patterns in the codebase and includes proper error handling and validation. |
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
PR Type
Enhancement
Description
Add custom selection tools to right-click context menu
Implement real-time menu updates when settings change
Add proper error handling and validation
Filter context menu to show only active tools
Diagram Walkthrough
File Walkthrough
menus.mjs
Enhanced context menu with custom tools support
src/background/menus.mjs
onClickMenu
custom_{index}
IDs to menurefreshMenu
to fetch user config onceindex.jsx
Custom selection tool message processing
src/content-script/index.jsx
{{selection}}
placeholder in custom promptsgetUserConfig
call before conditional logicSelectionTools.jsx
Real-time menu refresh functionality
src/popup/sections/SelectionTools.jsx
Browser
import for runtime messagingREFRESH_MENU
messages on tool changes.catch(console.error)
to all sendMessage callsSummary by CodeRabbit
New Features
Refactor