|
@@ -14,6 +14,7 @@ import {
|
|
|
import { loadMathJax } from '../../mathjax/load-mathjax'
|
|
import { loadMathJax } from '../../mathjax/load-mathjax'
|
|
|
import { descendantsOfNodeWithType } from '../utils/tree-query'
|
|
import { descendantsOfNodeWithType } from '../utils/tree-query'
|
|
|
import {
|
|
import {
|
|
|
|
|
+ MathContainer,
|
|
|
mathAncestorNode,
|
|
mathAncestorNode,
|
|
|
parseMathContainer,
|
|
parseMathContainer,
|
|
|
} from '../utils/tree-operations/math'
|
|
} from '../utils/tree-operations/math'
|
|
@@ -92,12 +93,13 @@ function buildTooltips(state: EditorState): readonly Tooltip[] {
|
|
|
|
|
|
|
|
for (const range of state.selection.ranges) {
|
|
for (const range of state.selection.ranges) {
|
|
|
if (range.empty) {
|
|
if (range.empty) {
|
|
|
- const pos = range.from
|
|
|
|
|
- const content = buildTooltipContent(state, pos)
|
|
|
|
|
- if (content) {
|
|
|
|
|
|
|
+ const mathContainer = getMathContainer(state, range.from)
|
|
|
|
|
+ const content = buildTooltipContent(state, mathContainer)
|
|
|
|
|
+ if (content && mathContainer) {
|
|
|
const tooltip: Tooltip = {
|
|
const tooltip: Tooltip = {
|
|
|
- pos,
|
|
|
|
|
|
|
+ pos: mathContainer.pos,
|
|
|
above: true,
|
|
above: true,
|
|
|
|
|
+ strictSide: true,
|
|
|
arrow: false,
|
|
arrow: false,
|
|
|
create() {
|
|
create() {
|
|
|
const dom = document.createElement('div')
|
|
const dom = document.createElement('div')
|
|
@@ -116,18 +118,21 @@ function buildTooltips(state: EditorState): readonly Tooltip[] {
|
|
|
return tooltips
|
|
return tooltips
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const buildTooltipContent = (
|
|
|
|
|
- state: EditorState,
|
|
|
|
|
- pos: number
|
|
|
|
|
-): HTMLDivElement | null => {
|
|
|
|
|
- // if anywhere inside Math, render the whole Math content
|
|
|
|
|
|
|
+const getMathContainer = (state: EditorState, pos: number) => {
|
|
|
|
|
+ // if anywhere inside Math, find the whole Math node
|
|
|
const ancestorNode = mathAncestorNode(state, pos)
|
|
const ancestorNode = mathAncestorNode(state, pos)
|
|
|
if (!ancestorNode) return null
|
|
if (!ancestorNode) return null
|
|
|
|
|
|
|
|
const [node] = descendantsOfNodeWithType(ancestorNode, 'Math', 'Math')
|
|
const [node] = descendantsOfNodeWithType(ancestorNode, 'Math', 'Math')
|
|
|
if (!node) return null
|
|
if (!node) return null
|
|
|
|
|
|
|
|
- const math = parseMathContainer(state, node, ancestorNode)
|
|
|
|
|
|
|
+ return parseMathContainer(state, node, ancestorNode)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const buildTooltipContent = (
|
|
|
|
|
+ state: EditorState,
|
|
|
|
|
+ math: MathContainer | null
|
|
|
|
|
+): HTMLDivElement | null => {
|
|
|
if (!math || !math.content.length) return null
|
|
if (!math || !math.content.length) return null
|
|
|
|
|
|
|
|
const element = document.createElement('div')
|
|
const element = document.createElement('div')
|