Skip to content

Commit 4f38ae5

Browse files
committed
wip: fix nested inline math
1 parent a2f462a commit 4f38ae5

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/utils/context.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,28 @@ const getInnerEquationBounds = (view: EditorView, pos?: number ):Bounds | null =
226226

227227
// ignore \$
228228
text = text.replaceAll("\\$", "\\R");
229+
pos = pos - bounds.inner_start;
229230

230231
const left = text.lastIndexOf("$", pos-1);
231232
const right = text.indexOf("$", pos);
233+
// console.log(left, right, text.slice(0, pos), text.slice(pos))
234+
if (left === -1 || right === -1) {
235+
const left2 = text.lastIndexOf("\\(", pos-1)
236+
const right2 = text.indexOf("\\)", pos)
237+
if (left2 === -1 || right2 === -1) {
238+
return bounds;
239+
} else {
232240

233-
if (left === -1 || right === -1) return bounds;
241+
const result = {
242+
inner_start: bounds.inner_start + left2 + 2,
243+
inner_end: bounds.inner_start + right2,
244+
outer_start: bounds.inner_start + left2,
245+
outer_end: bounds.inner_start + right2 + 2,
246+
}
247+
console.log(view.state.sliceDoc(result.outer_start, result.outer_end))
248+
return result
249+
}
250+
}
234251

235252
return {
236253
inner_start: left + 1,

0 commit comments

Comments
 (0)