fix(canvas): add handler for focus loss for hotkey operations#2701
Merged
waleedlatif1 merged 1 commit intostagingfrom Jan 7, 2026
Merged
fix(canvas): add handler for focus loss for hotkey operations#2701waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1 merged 1 commit intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This PR fixes a bug where the Shift key state would get stuck in "pressed" mode when the window lost focus while the key was held down, causing unintended selection behavior in the canvas.
Changes
- Added
handleFocusLoss()function to reset bothisShiftPressedandisSelectionDragActivestates - Added
handleVisibilityChange()to detect when the document becomes hidden (tab switch, minimize) - Added event listeners for
window.bluranddocument.visibilitychangeevents - Properly cleaned up new event listeners in the effect cleanup function
Impact
This fix prevents the canvas from being stuck in selection mode when users:
- Switch tabs while holding Shift
- Use Alt+Tab with Shift pressed
- Minimize/restore the window during selection operations
The implementation is clean, follows React best practices with proper cleanup, and handles both focus loss scenarios (blur and visibility change) comprehensively.
Confidence Score: 5/5
- This PR is safe to merge - it's a well-contained bug fix with proper cleanup and no breaking changes
- The fix is minimal, targeted, and addresses a specific UX bug. The implementation follows React patterns correctly with proper event listener cleanup, handles both blur and visibility change scenarios, and doesn't introduce any new dependencies or side effects. The changes are isolated to a single useEffect hook.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx | 5/5 | Added focus loss handlers to reset shift key and selection drag states, preventing stuck modifier keys when window loses focus |
Sequence Diagram
sequenceDiagram
participant User
participant Window
participant Component
participant ReactFlow
Note over User,ReactFlow: Normal Shift Key Operation
User->>Window: Press Shift key
Window->>Component: keydown event
Component->>Component: setIsShiftPressed(true)
Component->>ReactFlow: selectionOnDrag=true
User->>Window: Release Shift key
Window->>Component: keyup event
Component->>Component: setIsShiftPressed(false)
Component->>ReactFlow: selectionOnDrag=false
Note over User,ReactFlow: Bug Fix - Focus Loss Handling
User->>Window: Press Shift key
Window->>Component: keydown event
Component->>Component: setIsShiftPressed(true)
Component->>Component: setIsSelectionDragActive(true) if dragging
User->>Window: Switch tab / Alt+Tab
Window->>Component: blur event
Component->>Component: handleFocusLoss()
Component->>Component: setIsShiftPressed(false)
Component->>Component: setIsSelectionDragActive(false)
Component->>ReactFlow: States reset to default
Note over User,ReactFlow: Visibility Change Handling
User->>Window: Press Shift key
Window->>Component: keydown event
Component->>Component: setIsShiftPressed(true)
User->>Window: Minimize window
Window->>Component: visibilitychange event
Component->>Component: handleVisibilityChange()
Component->>Component: handleFocusLoss() if hidden
Component->>Component: Reset both states
Component->>ReactFlow: States reset to default
waleedlatif1
added a commit
that referenced
this pull request
Jan 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Type of Change
Testing
Tested manually
Checklist