Skip to content

fix(context-menu): open editor menu on right-click over resize overlays#3750

Open
dawidbudaszewski wants to merge 1 commit into
superdoc-dev:mainfrom
dawidbudaszewski:fix/context-menu-over-resize-overlays
Open

fix(context-menu): open editor menu on right-click over resize overlays#3750
dawidbudaszewski wants to merge 1 commit into
superdoc-dev:mainfrom
dawidbudaszewski:fix/context-menu-over-resize-overlays

Conversation

@dawidbudaszewski

@dawidbudaszewski dawidbudaszewski commented Jun 17, 2026

Copy link
Copy Markdown

Summary

Right-clicking on a table (or image) sometimes shows the browser's native context menu instead of SuperDoc's editor menu — reproducible whenever the blue resize handles are under the cursor. This makes actions like Edit table unreachable in that spot.
Before:
Screenshot 2026-06-18 at 00 31 43
After:
Screenshot 2026-06-18 at 00 26 21

Root cause

The table/image resize overlays (.superdoc-table-resize-overlay / .superdoc-image-resize-overlay, rendered by TableResizeOverlay.vue / ImageResizeOverlay.vue) are mounted as siblings of the editor surface, not inside it:

<div class="super-editor">
  <div class="editor-element …">         ← editor surface (getEditorSurfaceElement)
  <ContextMenu />
  <div class="superdoc-table-resize-overlay">  ← sibling, holds the resize handles

ContextMenu.vue's isEventWithinContextMenuTargets() only treats the editor surface and the ProseMirror view DOM as in-editor. So when a right-click lands on a resize handle, handleRightClick bails early, never calls event.preventDefault(), and the native menu wins. (The ProseMirror handleDOMEvents.contextmenu and the PresentationInputBridge forwarder also skip it for the same reason.)

Fix

Treat targets within the resize overlays as in-editor. Added a small pure helper isWithinResizeOverlay(target) in contextmenu-helpers.js and used it in isEventWithinContextMenuTargets(). Because the menu context (position, isInTable, etc.) is resolved from the cursor coordinates (getEditorContextposAtCoords), the correct items (e.g. Edit table) are shown even though the DOM target is the overlay handle.

Testing

  • pnpm exec vitest run for the context-menu suite — all pass (165), including 3 new unit tests for isWithinResizeOverlay.
  • Prettier clean; ESLint clean.
  • Manually verified in an editor build: right-clicking directly on the blue resize handles now opens the SuperDoc context menu with the table actions.

Made with Cursor

The table and image resize overlays (the column/row resize handles shown
on hover) render as siblings of the editor surface rather than inside it.
A right-click landing on one of their handles therefore fell outside the
context-menu target surfaces, so SuperDoc never called preventDefault and
the browser's native context menu appeared instead of the editor menu.

Treat targets within `.superdoc-table-resize-overlay` and
`.superdoc-image-resize-overlay` as in-editor so the custom context menu
(e.g. "Edit table") opens reliably. The table position is still resolved
from the cursor coordinates, so the correct menu items are shown.

Adds a pure `isWithinResizeOverlay` helper with unit tests.

Co-authored-by: Cursor <cursoragent@cursor.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5bcf94f24

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +373 to +374
if (isWithinResizeOverlay(target)) {
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope resize overlay checks to this editor

When multiple SuperDoc editors are mounted, each ContextMenu instance has document-level contextmenu listeners, but this new early return treats any .superdoc-table-resize-overlay or .superdoc-image-resize-overlay in the document as belonging to this editor. Right-clicking a resize handle in editor A will therefore also make editor B's handler run, call preventDefault(), dispatch/open against editor B using editor A's coordinates, and potentially focus or show a stale menu for the wrong instance. Please only accept overlays associated with this ContextMenu's own .super-editor/surface before returning true.

Useful? React with 👍 / 👎.

@shri-scale shri-scale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants