-
Notifications
You must be signed in to change notification settings - Fork 851
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?
Changes from 5 commits
ac11758
06179d9
7cd1777
fe4b856
0ea8bef
ee84477
7a86413
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -284,8 +284,24 @@ async function prepareForRightClickMenu() { | |||||||||||||||||||||||||||||||
| if (message.type === 'CREATE_CHAT') { | ||||||||||||||||||||||||||||||||
| const data = message.data | ||||||||||||||||||||||||||||||||
| let prompt = '' | ||||||||||||||||||||||||||||||||
| const userConfig = await getUserConfig() | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (data.itemId in toolsConfig) { | ||||||||||||||||||||||||||||||||
| prompt = await toolsConfig[data.itemId].genPrompt(data.selectionText) | ||||||||||||||||||||||||||||||||
| } else if (data.itemId.startsWith('custom_')) { | ||||||||||||||||||||||||||||||||
| // Handle custom selection tools from context menu | ||||||||||||||||||||||||||||||||
| const customIndex = parseInt(data.itemId.replace('custom_', ''), 10) | ||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||
| !isNaN(customIndex) && | ||||||||||||||||||||||||||||||||
| customIndex >= 0 && | ||||||||||||||||||||||||||||||||
| userConfig.customSelectionTools && | ||||||||||||||||||||||||||||||||
| customIndex < userConfig.customSelectionTools.length | ||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||
| const customTool = userConfig.customSelectionTools[customIndex] | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| if ( | |
| !isNaN(customIndex) && | |
| customIndex >= 0 && | |
| userConfig.customSelectionTools && | |
| customIndex < userConfig.customSelectionTools.length | |
| ) { | |
| const customTool = userConfig.customSelectionTools[customIndex] | |
| const customSelectionTools = userConfig.customSelectionTools | |
| if ( | |
| !isNaN(customIndex) && | |
| customIndex >= 0 && | |
| customSelectionTools && | |
| customIndex < customSelectionTools.length | |
| ) { | |
| const customTool = 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.
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've simplified the validation logic using optional chaining (userConfig.customSelectionTools?.[customIndex]) and removed the complex bounds checking conditions. This makes the code more concise and follows modern JavaScript patterns used elsewhere in the codebase. Changes made in commit ee84477.
PeterDaveHello marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types' | |||||||||
| import { useState } from 'react' | ||||||||||
| import { defaultConfig } from '../../config/index.mjs' | ||||||||||
| import { PencilIcon, TrashIcon } from '@primer/octicons-react' | ||||||||||
| import Browser from 'webextension-polyfill' | ||||||||||
|
|
||||||||||
| SelectionTools.propTypes = { | ||||||||||
| config: PropTypes.object.isRequired, | ||||||||||
|
|
@@ -36,7 +37,7 @@ export function SelectionTools({ config, updateConfig }) { | |||||||||
| {t('Cancel')} | ||||||||||
| </button> | ||||||||||
| <button | ||||||||||
| onClick={(e) => { | ||||||||||
| onClick={async (e) => { | ||||||||||
| e.preventDefault() | ||||||||||
| if (!editingTool.name) { | ||||||||||
| setErrorMessage(t('Name is required')) | ||||||||||
|
|
@@ -47,14 +48,17 @@ export function SelectionTools({ config, updateConfig }) { | |||||||||
| return | ||||||||||
| } | ||||||||||
| if (editingIndex === -1) { | ||||||||||
| updateConfig({ | ||||||||||
| await updateConfig({ | ||||||||||
| customSelectionTools: [...config.customSelectionTools, editingTool], | ||||||||||
| }) | ||||||||||
| } else { | ||||||||||
| const customSelectionTools = [...config.customSelectionTools] | ||||||||||
| customSelectionTools[editingIndex] = editingTool | ||||||||||
| updateConfig({ customSelectionTools }) | ||||||||||
| await updateConfig({ customSelectionTools }) | ||||||||||
| } | ||||||||||
| Browser.runtime.sendMessage({ | ||||||||||
| type: 'REFRESH_MENU', | ||||||||||
| }) | ||||||||||
PeterDaveHello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| Browser.runtime.sendMessage({ | |
| type: 'REFRESH_MENU', | |
| }) | |
| }).catch(console.error) |
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.
@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.
Extracted refreshContextMenu() helper function to eliminate code duplication across multiple sendMessage calls. (7a86413)
Outdated
Copilot
AI
Aug 30, 2025
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 sendMessage call lacks error handling. Add .catch(console.error) to handle potential messaging failures, consistent with the pattern mentioned in the PR description.
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.
Extracted refreshContextMenu() helper function to eliminate code duplication across multiple sendMessage calls. (7a86413)
Outdated
Copilot
AI
Aug 29, 2025
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.
Missing error handling for Browser.runtime.sendMessage call. Add .catch(console.error) to handle potential messaging failures consistently with other similar calls in the codebase.
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.
@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.
Extracted refreshContextMenu() helper function to eliminate code duplication across multiple sendMessage calls. (7a86413)
Outdated
Copilot
AI
Aug 30, 2025
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 sendMessage call lacks error handling. Add .catch(console.error) to handle potential messaging failures, consistent with the pattern mentioned in the PR description.
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.
Extracted refreshContextMenu() helper function to eliminate code duplication across multiple sendMessage calls. (7a86413)
Outdated
Copilot
AI
Aug 29, 2025
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.
Missing error handling for Browser.runtime.sendMessage call. Add .catch(console.error) to handle potential messaging failures consistently with other similar calls in the codebase.
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.
@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.
Extracted refreshContextMenu() helper function to eliminate code duplication across multiple sendMessage calls. (7a86413)
Outdated
Copilot
AI
Aug 30, 2025
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 sendMessage call lacks error handling. Add .catch(console.error) to handle potential messaging failures, consistent with the pattern mentioned in the PR description.
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.
Extracted refreshContextMenu() helper function to eliminate code duplication across multiple sendMessage calls. (7a86413)
Outdated
Copilot
AI
Aug 29, 2025
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.
Missing error handling for Browser.runtime.sendMessage call. Add .catch(console.error) to handle potential messaging failures consistently with other similar calls in the codebase.
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.
@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.
Extracted refreshContextMenu() helper function to eliminate code duplication across multiple sendMessage calls. (7a86413)
Outdated
Copilot
AI
Aug 30, 2025
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 sendMessage call lacks error handling. Add .catch(console.error) to handle potential messaging failures, consistent with the pattern mentioned in the PR description.
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.
Extracted refreshContextMenu() helper function to eliminate code duplication across multiple sendMessage calls. (7a86413)
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.
Potential runtime error if
userConfig.customSelectionToolsis undefined or null. Add a safety check before the loop to ensure the array exists.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've modernized the code by replacing the traditional for loop with
forEachfor better readability and consistency with the codebase patterns. This change was made in commit ee84477.