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
This commit is contained in:
David 2024-09-03 16:23:47 +01:00 committed by Copybot
parent 4802d04fb0
commit f4c57fce4c
2 changed files with 20 additions and 0 deletions

View file

@ -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)
}

View file

@ -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
}