diff --git a/services/web/frontend/js/features/source-editor/extensions/context-menu.ts b/services/web/frontend/js/features/source-editor/extensions/context-menu.ts index 4dbf626f96..bace4cf171 100644 --- a/services/web/frontend/js/features/source-editor/extensions/context-menu.ts +++ b/services/web/frontend/js/features/source-editor/extensions/context-menu.ts @@ -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() + const isTouchOnlyInput = typeof window.matchMedia === 'function' && window.matchMedia('(pointer: coarse)').matches && @@ -206,6 +209,7 @@ function openContextMenuAtPosition( y: clientY, }), ], + annotations: [openContextMenuAnnotation.of(true)], }) } diff --git a/services/web/frontend/js/features/source-editor/languages/latex/open-autocomplete.ts b/services/web/frontend/js/features/source-editor/languages/latex/open-autocomplete.ts index 8abaf0a9c4..431363f11a 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/open-autocomplete.ts +++ b/services/web/frontend/js/features/source-editor/languages/latex/open-autocomplete.ts @@ -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) }