Skip to content

Commit 9bf31d3

Browse files
authored
fix terminal keyboard shortcut error when adding content to context (#5161)
## Fix terminal keyboard shortcut error when adding content to context **Fixes:** [#2276](#2276) **Problem:** - Using keyboard shortcuts to add terminal content to context threw error: "Cannot read properties of undefined (reading 'selection')" - Context menu worked correctly, but keyboard shortcuts failed **Root Cause:** - Command handler accessed `args.selection` without null checking - When triggered via keyboard shortcut, VS Code passes `undefined` for `args` parameter - When triggered via context menu, VS Code passes an object with `selection` property **Solution:** - Changed `args.selection` to `args?.selection` using optional chaining - Maintains existing fallback behavior when no selection is available - Preserves backward compatibility with context menu functionality **Files Modified:** - `src/activate/registerTerminalActions.ts` - Added null safety for args parameter **Testing:** - ✅ Keyboard shortcuts now work without errors - ✅ Context menu functionality preserved - ✅ Fallback to `Terminal.getTerminalContents()` works in both scenarios
1 parent 4335796 commit 9bf31d3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/activate/registerTerminalActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const registerTerminalAction = (
2020
) => {
2121
context.subscriptions.push(
2222
vscode.commands.registerCommand(getTerminalCommand(command), async (args: any) => {
23-
let content = args.selection
23+
let content = args?.selection
2424

2525
if (!content || content === "") {
2626
content = await Terminal.getTerminalContents(promptType === "TERMINAL_ADD_TO_CONTEXT" ? -1 : 1)

0 commit comments

Comments
 (0)