Merge pull request #32007 from overleaf/mg-context-ctrl-click

[web] Only allow ctrl+click context menu trigger for macos

GitOrigin-RevId: ca0476bd94e25e92e6fa86f5bcaf8a209212c1b9
This commit is contained in:
Malik Glossop
2026-03-05 12:03:46 +01:00
committed by Copybot
parent ee294c524d
commit 87c7b23107
3 changed files with 9 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ import {
Annotation,
} from '@codemirror/state'
import { closeAllContextMenusEffect } from '../utils/close-all-context-menus-effect'
import { isContextMenuMouseEvent } from '../utils/context-menu-mouse-event'
export const openContextMenuEffect = StateEffect.define<{
pos: number
@@ -352,7 +353,7 @@ const editorContextMenuHandlers = (): Extension =>
mousedown(event: MouseEvent, view: EditorView) {
const target = event.target as HTMLElement
const isGutter = isClickOnGutter(target)
const isRightClick = event.button === 2 || event.ctrlKey
const isRightClick = isContextMenuMouseEvent(event)
// Close menu on any click except right-click on non-gutter
if (!isRightClick || isGutter) {

View File

@@ -16,6 +16,7 @@ import {
Transaction,
} from '@codemirror/state'
import { v4 as uuid } from 'uuid'
import { isContextMenuMouseEvent } from '../utils/context-menu-mouse-event'
export const addNewCommentRangeEffect = StateEffect.define<Range<Decoration>>()
@@ -66,7 +67,7 @@ export const reviewTooltip = (editorContextMenuEnabled = false): Extension => {
EditorView.domEventHandlers({
mousedown: (event, view) => {
// Hide tooltip when opening the context menu
if (editorContextMenuEnabled && (event.button === 2 || event.ctrlKey)) {
if (editorContextMenuEnabled && isContextMenuMouseEvent(event)) {
return false
}

View File

@@ -0,0 +1,5 @@
import { isMac } from '@/shared/utils/os'
export function isContextMenuMouseEvent(event: MouseEvent): boolean {
return event.button === 2 || (isMac && event.button === 0 && event.ctrlKey)
}