Skip to content

fix: position browser context menu at cursor with edge flipping#682

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/right-click-fix
Apr 15, 2026
Merged

fix: position browser context menu at cursor with edge flipping#682
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/right-click-fix

Conversation

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Summary

  • Use screen.getCursorScreenPoint() in main process as ground truth for cursor position, immune to guest/renderer coordinate space mismatches
  • Convert screen coordinates to CSS viewport via (screenX - window.screenX) / zoomFactor in the renderer, handling UI zoom correctly
  • Flip the context menu to the opposite side of the cursor when it would overflow viewport edges (right, bottom, or corner)
  • Self-correct via useLayoutEffect + getBoundingClientRect() to compensate for any CSS containing block offsets
  • Dismiss context menu on left/middle click in guest webview but skip right-click to avoid flash from dismiss-then-reopen

Test plan

  • Unit tests for screen-to-viewport coordinate conversion at multiple zoom levels
  • Unit tests for CSS containing block self-correction math
  • Unit tests for viewport edge flipping (right, bottom, corner, clamp-to-zero, boundary)
  • Unit tests for context menu IPC dispatch (params passthrough, navigation state, renderer unavailable)
  • Unit tests for dismiss behavior (left-click, middle-click, right-click skip, mouseMove ignore)
  • Unit tests for cleanup/teardown
  • Manual: right-click in browser pane → menu top-left at cursor
  • Manual: right-click near right/bottom edge → menu flips direction
  • Manual: right-click at various UI zoom levels → menu stays at cursor

The right-click context menu was appearing offset from the cursor due to
coordinate space mismatches between the guest webview process and the
renderer. Switch to using screen.getCursorScreenPoint() as ground truth,
converting to CSS viewport coordinates via (screenX - window.screenX) /
zoomFactor. Add viewport edge detection that flips the menu to the
opposite side of the cursor when it would overflow.
@Jinwoo-H
Jinwoo-H merged commit ae11e7f into main Apr 15, 2026
1 check passed
thomaszdxsn pushed a commit to thomaszdxsn/orca that referenced this pull request Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant