-
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?
Changes from all 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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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, | ||||||||||||||
|
@@ -17,6 +18,13 @@ const defaultTool = { | |||||||||||||
active: true, | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Helper function to refresh context menu | ||||||||||||||
const refreshContextMenu = () => { | ||||||||||||||
Browser.runtime.sendMessage({ | ||||||||||||||
type: 'REFRESH_MENU', | ||||||||||||||
}) | ||||||||||||||
Comment on lines
+21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I see the reference to lines 21-25 where the |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
export function SelectionTools({ config, updateConfig }) { | ||||||||||||||
const { t } = useTranslation() | ||||||||||||||
const [editing, setEditing] = useState(false) | ||||||||||||||
|
@@ -36,7 +44,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 +55,15 @@ 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 }) | ||||||||||||||
} | ||||||||||||||
refreshContextMenu() | ||||||||||||||
setEditing(false) | ||||||||||||||
}} | ||||||||||||||
> | ||||||||||||||
|
@@ -102,11 +111,12 @@ export function SelectionTools({ config, updateConfig }) { | |||||||||||||
<input | ||||||||||||||
type="checkbox" | ||||||||||||||
checked={config.activeSelectionTools.includes(key)} | ||||||||||||||
onChange={(e) => { | ||||||||||||||
onChange={async (e) => { | ||||||||||||||
const checked = e.target.checked | ||||||||||||||
const activeSelectionTools = config.activeSelectionTools.filter((i) => i !== key) | ||||||||||||||
if (checked) activeSelectionTools.push(key) | ||||||||||||||
updateConfig({ activeSelectionTools }) | ||||||||||||||
await updateConfig({ activeSelectionTools }) | ||||||||||||||
refreshContextMenu() | ||||||||||||||
}} | ||||||||||||||
/> | ||||||||||||||
{t(toolsConfig[key].label)} | ||||||||||||||
|
@@ -122,10 +132,11 @@ export function SelectionTools({ config, updateConfig }) { | |||||||||||||
<input | ||||||||||||||
type="checkbox" | ||||||||||||||
checked={tool.active} | ||||||||||||||
onChange={(e) => { | ||||||||||||||
onChange={async (e) => { | ||||||||||||||
const customSelectionTools = [...config.customSelectionTools] | ||||||||||||||
customSelectionTools[index] = { ...tool, active: e.target.checked } | ||||||||||||||
updateConfig({ customSelectionTools }) | ||||||||||||||
await updateConfig({ customSelectionTools }) | ||||||||||||||
refreshContextMenu() | ||||||||||||||
}} | ||||||||||||||
/> | ||||||||||||||
{tool.name} | ||||||||||||||
|
@@ -145,11 +156,12 @@ export function SelectionTools({ config, updateConfig }) { | |||||||||||||
</div> | ||||||||||||||
<div | ||||||||||||||
style={{ cursor: 'pointer' }} | ||||||||||||||
onClick={(e) => { | ||||||||||||||
onClick={async (e) => { | ||||||||||||||
e.preventDefault() | ||||||||||||||
const customSelectionTools = [...config.customSelectionTools] | ||||||||||||||
customSelectionTools.splice(index, 1) | ||||||||||||||
updateConfig({ customSelectionTools }) | ||||||||||||||
await updateConfig({ customSelectionTools }) | ||||||||||||||
refreshContextMenu() | ||||||||||||||
}} | ||||||||||||||
> | ||||||||||||||
<TrashIcon /> | ||||||||||||||
|
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. IfcustomTool.prompt
is undefined or null, the.replace()
call will throw an error. Add a check forcustomTool.prompt
before calling.replace()
.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.