Skip to content

Add support for custom Selection Tools in right-click context menu#885

Open
Copilot wants to merge 7 commits into
masterfrom
copilot/fix-778
Open

Add support for custom Selection Tools in right-click context menu#885
Copilot wants to merge 7 commits into
masterfrom
copilot/fix-778

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 29, 2025

  • Initial implementation plan
  • Add custom Selection Tools support to right-click context menu
  • Add menu refresh functionality to Selection Tools settings
  • Fix parseInt usage with explicit radix and NaN checking
  • Add error handling for Browser.runtime.sendMessage calls
  • Remove unnecessary .catch(console.error) for REFRESH_MENU calls to match existing patterns
  • Modernize code patterns: use forEach instead of traditional for loops and optional chaining for array access
  • Reduce code duplication by extracting refreshContextMenu helper function
  • Improve parseInt validation with NaN and bounds checking
  • Add optional chaining for safer array access in background menus
  • Test build and lint 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

flowchart LR
  A["Settings UI"] -- "REFRESH_MENU" --> B["Background Script"]
  B -- "getUserConfig()" --> C["User Config"]
  C --> D["Context Menu Builder"]
  D --> E["Active Tools Only"]
  F["Right-click"] --> G["Content Script"]
  G -- "custom_ handler" --> H["Custom Tool Execution"]
Loading

File Walkthrough

Relevant files
Enhancement
menus.mjs
Enhanced context menu with custom tools support                   

src/background/menus.mjs

  • Add custom selection tool handling in onClickMenu
  • Filter context menu to show only active default tools
  • Add custom tools with custom_{index} IDs to menu
  • Enhance refreshMenu to fetch user config once
+31/-7   
index.jsx
Custom selection tool message processing                                 

src/content-script/index.jsx

  • Add custom tool message handling in runtime listener
  • Parse custom tool index with proper validation
  • Replace {{selection}} placeholder in custom prompts
  • Move getUserConfig call before conditional logic
+16/-1   
SelectionTools.jsx
Real-time menu refresh functionality                                         

src/popup/sections/SelectionTools.jsx

  • Add Browser import for runtime messaging
  • Send REFRESH_MENU messages on tool changes
  • Make event handlers async with error handling
  • Add .catch(console.error) to all sendMessage calls
+30/-9   

Summary by CodeRabbit

  • New Features

    • Added custom selection tools to the context menu with prompt support.
    • Context menu now reflects user-enabled default and custom tools.
    • Immediate menu updates after adding, editing, toggling, or deleting tools.
    • Selection-triggered chat uses appropriate prompts, including custom ones.
  • Refactor

    • Consolidated user configuration fetching to reduce redundant calls.
    • Menu rendering now respects the “hide context menu” setting and exits early.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants