From f4c57fce4cd5007997fab4980426b5bad1f0e860 Mon Sep 17 00:00:00 2001 From: David <33458145+davidmcpowell@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:23:47 +0100 Subject: [PATCH] Merge pull request #20246 from overleaf/dp-math-preview-closing-delimiter Don't show math preview tooltip if the node has a parse error GitOrigin-RevId: 330ebb945c70da4b5fe9ee4ee2f149a95435899b --- .../source-editor/extensions/math-preview.tsx | 3 +++ .../utils/tree-operations/common.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/services/web/frontend/js/features/source-editor/extensions/math-preview.tsx b/services/web/frontend/js/features/source-editor/extensions/math-preview.tsx index d5158405b9..effcaf6436 100644 --- a/services/web/frontend/js/features/source-editor/extensions/math-preview.tsx +++ b/services/web/frontend/js/features/source-editor/extensions/math-preview.tsx @@ -25,6 +25,7 @@ import { isSplitTestEnabled } from '@/utils/splitTestUtils' import ReactDOM from 'react-dom' import { SplitTestProvider } from '@/shared/context/split-test-context' import SplitTestBadge from '@/shared/components/split-test-badge' +import { nodeHasError } from '../utils/tree-operations/common' const REPOSITION_EVENT = 'editor:repositionMathTooltips' @@ -134,6 +135,8 @@ const getMathContainer = (state: EditorState, pos: number) => { const [node] = descendantsOfNodeWithType(ancestorNode, 'Math', 'Math') if (!node) return null + if (nodeHasError(ancestorNode)) return null + return parseMathContainer(state, node, ancestorNode) } diff --git a/services/web/frontend/js/features/source-editor/utils/tree-operations/common.ts b/services/web/frontend/js/features/source-editor/utils/tree-operations/common.ts index 1355057d9e..69fe55dfcb 100644 --- a/services/web/frontend/js/features/source-editor/utils/tree-operations/common.ts +++ b/services/web/frontend/js/features/source-editor/utils/tree-operations/common.ts @@ -61,3 +61,20 @@ export const getOptionalArgumentText = ( return state.doc.sliceString(shortArgNode.from, shortArgNode.to) } } + +export const nodeHasError = (node: SyntaxNode): boolean => { + let hasError = false + + node.cursor().iterate(({ type }) => { + if (hasError) return false + + if (type.isError) { + hasError = true + return false + } + + return true + }) + + return hasError +}