Merge pull request #31952 from overleaf/mg-context-menu-autocomplete
Do not open autocomplete menu after right-click in empty curly braces GitOrigin-RevId: c5f6cce9a093ce0f3aad08f5968e743ce373efc9
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
TransactionSpec,
|
||||
EditorSelection,
|
||||
Prec,
|
||||
Annotation,
|
||||
} from '@codemirror/state'
|
||||
import { closeAllContextMenusEffect } from '../utils/close-all-context-menus-effect'
|
||||
|
||||
@@ -24,6 +25,8 @@ export const openContextMenuEffect = StateEffect.define<{
|
||||
|
||||
export const closeContextMenuEffect = StateEffect.define()
|
||||
|
||||
export const openContextMenuAnnotation = Annotation.define<boolean>()
|
||||
|
||||
const isTouchOnlyInput =
|
||||
typeof window.matchMedia === 'function' &&
|
||||
window.matchMedia('(pointer: coarse)').matches &&
|
||||
@@ -206,6 +209,7 @@ function openContextMenuAtPosition(
|
||||
y: clientY,
|
||||
}),
|
||||
],
|
||||
annotations: [openContextMenuAnnotation.of(true)],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+9
-1
@@ -2,12 +2,20 @@ import { EditorView } from '@codemirror/view'
|
||||
import { startCompletion } from '@codemirror/autocomplete'
|
||||
import { Transaction } from '@codemirror/state'
|
||||
import { isInEmptyArgumentNodeForAutocomplete } from '../../utils/tree-query'
|
||||
import { openContextMenuAnnotation } from '../../extensions/context-menu'
|
||||
|
||||
// start autocompletion when the cursor enters an empty pair of braces
|
||||
// but skip updates caused by context menu open or remote transactions
|
||||
export const openAutocomplete = () => {
|
||||
return EditorView.updateListener.of(update => {
|
||||
if (update.selectionSet || update.docChanged) {
|
||||
if (!update.transactions.some(tr => tr.annotation(Transaction.remote))) {
|
||||
if (
|
||||
!update.transactions.some(
|
||||
tr =>
|
||||
tr.annotation(Transaction.remote) ||
|
||||
tr.annotation(openContextMenuAnnotation)
|
||||
)
|
||||
) {
|
||||
if (isInEmptyArgumentNodeForAutocomplete(update.state)) {
|
||||
startCompletion(update.view)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user