Skip to content

Commit 170367c

Browse files
fix: prevent copilot keyboard shortcuts from triggering when panel is inactive
The OptionsSelector component was capturing keyboard events (1-9 number keys and Enter) globally on the document, causing accidental option selections when users were interacting with other parts of the application. This fix adds a check to only handle keyboard shortcuts when the copilot panel is the active tab, preventing the shortcuts from interfering with other workflows. Co-authored-by: Emir Karabeg <emir-karabeg@users.noreply.github.com>
1 parent 3ef6b05 commit 170367c

File tree

1 file changed

+7
-3
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/tool-call

1 file changed

+7
-3
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/tool-call/tool-call.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { ParallelTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/compo
2323
import { getDisplayValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block'
2424
import { getBlock } from '@/blocks/registry'
2525
import type { CopilotToolCall } from '@/stores/panel'
26-
import { useCopilotStore } from '@/stores/panel'
26+
import { useCopilotStore, usePanelStore } from '@/stores/panel'
2727
import type { SubAgentContentBlock } from '@/stores/panel/copilot/types'
2828
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
2929

@@ -341,16 +341,20 @@ export function OptionsSelector({
341341
const [hoveredIndex, setHoveredIndex] = useState(-1)
342342
const [chosenKey, setChosenKey] = useState<string | null>(selectedOptionKey)
343343
const containerRef = useRef<HTMLDivElement>(null)
344+
const activeTab = usePanelStore((s) => s.activeTab)
344345

345346
const isLocked = chosenKey !== null
346347

347-
// Handle keyboard navigation - only for the active options selector
348+
// Handle keyboard navigation - only for the active options selector when copilot is active
348349
useEffect(() => {
349350
if (isInteractionDisabled || !enableKeyboardNav || isLocked) return
350351

351352
const handleKeyDown = (e: KeyboardEvent) => {
352353
if (e.defaultPrevented) return
353354

355+
// Only handle keyboard shortcuts when the copilot panel is active
356+
if (activeTab !== 'copilot') return
357+
354358
const activeElement = document.activeElement
355359
const isInputFocused =
356360
activeElement?.tagName === 'INPUT' ||
@@ -387,7 +391,7 @@ export function OptionsSelector({
387391

388392
document.addEventListener('keydown', handleKeyDown)
389393
return () => document.removeEventListener('keydown', handleKeyDown)
390-
}, [isInteractionDisabled, enableKeyboardNav, isLocked, sortedOptions, hoveredIndex, onSelect])
394+
}, [isInteractionDisabled, enableKeyboardNav, isLocked, sortedOptions, hoveredIndex, onSelect, activeTab])
391395

392396
if (sortedOptions.length === 0) return null
393397

0 commit comments

Comments
 (0)