Skip to content

fix: add jump_from_cursor support for math equations - #2606

Draft
hooyuser wants to merge 1 commit into
Myriad-Dreamin:mainfrom
hooyuser:math-jump
Draft

fix: add jump_from_cursor support for math equations#2606
hooyuser wants to merge 1 commit into
Myriad-Dreamin:mainfrom
hooyuser:math-jump

Conversation

@hooyuser

Copy link
Copy Markdown
Contributor

Description

Fixes #2485.

Previously, jump_from_cursor only handled the leaf syntax node before the cursor when its SyntaxKind was Text or MathText. It took that syntax node’s Span, scanned all glyph spans in all frames, and jumped if a glyph had the same Span.

This PR adds conservative support for math equations. Syntax nodes are classified into three categories:

  • Confident: the syntax node’s Span is definitely a glyph Span
  • Unsure: it is unclear whether the syntax node’s Span is a glyph Span
  • Impossible: the syntax node’s Span is definitely not a glyph Span

When the cursor is between two leaf syntax nodes inside an Equation subtree, the algorithm searches outward in the order left1 -> right1 -> left2 -> right2. It ignores Impossible syntax nodes, collects Unsure and Confident spans as candidates, and stops after collecting one Confident span. This search is limited to the current Equation subtree.

After that, the algorithm scans all glyph spans in all frames. If a glyph Span matches one of the candidate syntax node spans, it jumps to that glyph position. Since the candidate list supports binary search, the per-glyph lookup adds a log(n) factor, where n is the candidate list length. In practice, the candidate list is usually small, so the overhead should stay controlled.

This PR currently only supports glyph spans. Some math syntax nodes, such as fraction bars, correspond to shape spans rather than glyph spans in final frames, so equations like $ zws / zws $ are still unsupported.

@hooyuser
hooyuser marked this pull request as draft June 21, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Click source to scroll for math

1 participant