mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Merge pull request #19617 from overleaf/dp-tooltip-alignment
Always render math preview tooltip at start of math content GitOrigin-RevId: b0af7aa3c0920b2a9b9930f27a580018de1d2f52
This commit is contained in:
@@ -3,6 +3,13 @@ import { EditorState } from '@codemirror/state'
|
||||
import { SyntaxNode, SyntaxNodeRef } from '@lezer/common'
|
||||
import { ancestorNodeOfType } from './ancestors'
|
||||
|
||||
export type MathContainer = {
|
||||
content: string
|
||||
displayMode: boolean
|
||||
passToMathJax: boolean
|
||||
pos: number
|
||||
}
|
||||
|
||||
export const mathAncestorNode = (state: EditorState, pos: number) =>
|
||||
ancestorNodeOfType(state, pos, '$MathContainer') ||
|
||||
ancestorNodeOfType(state, pos, 'EquationEnvironment') ||
|
||||
@@ -13,7 +20,7 @@ export const parseMathContainer = (
|
||||
state: EditorState,
|
||||
nodeRef: SyntaxNodeRef,
|
||||
ancestorNode: SyntaxNode
|
||||
) => {
|
||||
): MathContainer | null => {
|
||||
// the content of the Math element, without braces
|
||||
const innerContent = state.doc.sliceString(nodeRef.from, nodeRef.to).trim()
|
||||
|
||||
@@ -24,6 +31,7 @@ export const parseMathContainer = (
|
||||
let content = innerContent
|
||||
let displayMode = false
|
||||
let passToMathJax = true
|
||||
let pos = nodeRef.from
|
||||
|
||||
if (ancestorNode.type.is('$Environment')) {
|
||||
const environmentName = getEnvironmentName(ancestorNode, state)
|
||||
@@ -37,6 +45,7 @@ export const parseMathContainer = (
|
||||
content = state.doc
|
||||
.sliceString(ancestorNode.from, ancestorNode.to)
|
||||
.trim()
|
||||
pos = ancestorNode.from
|
||||
}
|
||||
|
||||
if (environmentName !== 'math') {
|
||||
@@ -52,5 +61,5 @@ export const parseMathContainer = (
|
||||
}
|
||||
}
|
||||
|
||||
return { content, displayMode, passToMathJax }
|
||||
return { content, displayMode, passToMathJax, pos }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user