Skip to content

fix(custom-selection): respect disableContextMenu so right-click isn't dead (SD-2944)#3171

Merged
caio-pizzol merged 1 commit intomainfrom
caio/SD-2944-disable-context-menu
May 5, 2026
Merged

fix(custom-selection): respect disableContextMenu so right-click isn't dead (SD-2944)#3171
caio-pizzol merged 1 commit intomainfrom
caio/SD-2944-disable-context-menu

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

The contextmenu DOM handler in the custom-selection extension preventDefaults every right-click inside the editor so SuperDoc's built-in menu can open over a preserved selection. `disableContextMenu: true` turns the built-in UI off but doesn't reach this handler, so the browser native menu and any consumer-attached `contextmenu` listener are both suppressed. Right-click on plain text inside the editor with the built-in menu disabled is dead today.

Short-circuits the handler when `editor.options.disableContextMenu` is true. Default behavior unchanged. The sibling mousedown-path selection preservation still runs, so a consumer rendering their own `contextmenu` listener sees the visible selection underneath while they decide what to render.

Without this, every consumer using `disableContextMenu` either has to render a menu unconditionally or live with the dead-click. With it, the flag does what it says and leaves SuperDoc out of the right-click flow.

Verified: `pnpm exec vitest run src/editors/v1/extensions/context-menu src/editors/v1/extensions/custom-selection src/editors/v1/components/context-menu` -> 207 passed (8 files, +2 new in custom-selection.test.js).

…t dead (SD-2944)

The contextmenu DOM handler in the custom-selection PM extension calls
event.preventDefault() unconditionally to keep focus and selection
visible while SuperDoc's built-in right-click menu opens. When the
consumer sets disableContextMenu: true the built-in UI refuses to
open, but the preventDefault still fires, so the browser's native
right-click menu and any consumer-attached contextmenu listener are
both suppressed. Right-click on plain text inside the editor goes
dead with no menu of any kind.

Short-circuits the contextmenu handler with a return false (no
preventDefault, no focus-preservation transaction) when
editor.options.disableContextMenu is true. Default behavior unchanged
for consumers using SuperDoc's built-in menu. The mousedown-side
selection preservation still runs, so a consumer rendering their own
menu sees the visible selection underneath.
@caio-pizzol caio-pizzol requested a review from a team as a code owner May 5, 2026 19:04
@linear
Copy link
Copy Markdown

linear Bot commented May 5, 2026

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@caio-pizzol caio-pizzol merged commit 74c9430 into main May 5, 2026
70 checks passed
@caio-pizzol caio-pizzol deleted the caio/SD-2944-disable-context-menu branch May 5, 2026 19:39
@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in @superdoc-dev/mcp v0.3.0-next.58

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in vscode-ext v2.3.0-next.102

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in @superdoc-dev/react v1.2.0-next.100

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in superdoc v1.30.0-next.58

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in superdoc-cli v0.8.0-next.75

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in superdoc-sdk v1.8.0-next.58

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