perf(tui): avoid repeated LaTeX scans

This commit is contained in:
chengyongru
2026-08-22 01:46:12 +08:00
committed by chengyongru
parent 375185210b
commit cbe4316e4b
+10 -7
View File
@@ -292,7 +292,7 @@ export function renderLatexAsUnicode(markdown: string): string {
} }
const explicitOpening = explicitMathOpeningAt(markdown, cursor) const explicitOpening = explicitMathOpeningAt(markdown, cursor)
const math = mathSpanAt(markdown, cursor, missingClosers) const math = mathSpanAt(markdown, cursor, explicitOpening, missingClosers)
if (math) { if (math) {
const converted = convertMath(math.content) const converted = convertMath(math.content)
if (converted !== null) { if (converted !== null) {
@@ -365,10 +365,9 @@ function explicitMathOpeningAt(markdown: string, start: number): string | null {
function mathSpanAt( function mathSpanAt(
markdown: string, markdown: string,
start: number, start: number,
explicitOpening: string | null,
missingClosers: Set<string>, missingClosers: Set<string>,
): MathSpan | null { ): MathSpan | null {
const explicitOpening = explicitMathOpeningAt(markdown, start)
if (explicitOpening === "\\[") { if (explicitOpening === "\\[") {
return delimitedMath(markdown, start, "\\[", "\\]", false, missingClosers) return delimitedMath(markdown, start, "\\[", "\\]", false, missingClosers)
} }
@@ -527,10 +526,14 @@ function markdownDestinationEnd(source: string, start: number): number | null {
if (angle) return start + angle.length if (angle) return start + angle.length
} }
const remainder = source.slice(start) if (
if (/^(?:https?:\/\/|mailto:)/u.test(remainder)) { source.startsWith("http://", start)
const match = remainder.match(/^[^\s<>]+/u) || source.startsWith("https://", start)
return match ? start + match[0].length : null || source.startsWith("mailto:", start)
) {
let end = start
while (end < source.length && !/[\s<>]/u.test(source[end] ?? "")) end += 1
return end
} }
return null return null
} }