소스 검색

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
David 1 년 전
부모
커밋
f4c57fce4c

+ 3 - 0
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)
 }
 

+ 17 - 0
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
+}