fix: add jump_from_cursor support for math equations - #2606
Draft
hooyuser wants to merge 1 commit into
Draft
Conversation
hooyuser
marked this pull request as draft
June 21, 2026 16:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2485.
Previously,
jump_from_cursoronly handled the leaf syntax node before the cursor when itsSyntaxKindwasTextorMathText. It took that syntax node’sSpan, scanned all glyph spans in all frames, and jumped if a glyph had the sameSpan.This PR adds conservative support for math equations. Syntax nodes are classified into three categories:
Confident: the syntax node’sSpanis definitely a glyphSpanUnsure: it is unclear whether the syntax node’sSpanis a glyphSpanImpossible: the syntax node’sSpanis definitely not a glyphSpanWhen the cursor is between two leaf syntax nodes inside an
Equationsubtree, the algorithm searches outward in the orderleft1 -> right1 -> left2 -> right2. It ignoresImpossiblesyntax nodes, collectsUnsureandConfidentspans as candidates, and stops after collecting oneConfidentspan. This search is limited to the currentEquationsubtree.After that, the algorithm scans all glyph spans in all frames. If a glyph
Spanmatches 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 alog(n)factor, wherenis 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.