-
Notifications
You must be signed in to change notification settings - Fork 839
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 4 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] |
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'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.
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.customSelectionTools
is undefined or null. Add a safety check before the loop to ensure the array exists.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've modernized the code by replacing the traditional for loop with
forEach
for better readability and consistency with the codebase patterns. This change was made in commit ee84477.