Skip to content

Fix #2974#2987

Open
zojize wants to merge 2 commits intoarnog:masterfrom
zojize:master
Open

Fix #2974#2987
zojize wants to merge 2 commits intoarnog:masterfrom
zojize:master

Conversation

@zojize
Copy link
Copy Markdown

@zojize zojize commented Mar 30, 2026

fixes #2974

Description

Fixes two related bugs when building parenthesized expressions via keyboard (e.g. typing 5 ) Home ( End /):

1. Empty/unresponsive mathfield after fraction insertion (#2974)

Typing / after a specific input sequence (e.g. 1 ) Home ( End) caused the field to become empty and unresponsive. The root cause was that deleting the implicit argument before inserting the fraction left the field empty, breaking cursor positioning. Subsequent Ctrl+A / Delete / retype also failed due to orphaned parent references left behind by deleteAtoms.

Fix: defer implicit argument deletion until after fraction insertion, then repair any orphaned parent pointers in root.body. Also adds null-safety guards throughout model.at() call sites and leftSibling traversals in getImplicitArgOffset.

2. Phantom duplicate caret

After the 1 ) Home ( sequence, two blinking cursors appeared instead of one. Two independent bugs contributed:

  • getStyleRuns in atom-class.ts pushed "first" atoms into a style run twice (missing continue after the type-check branch), causing them to render twice.
  • insertSmartFence case 2.2 in keyboard-input.ts didn't filter "first" sentinel atoms out of extractAtoms results when the extraction range started at offset 0. This caused root.body and leftright.body to share the same first atom object — so setting .caret on it produced a caret in both render locations.

Demo

Before

Screen.Recording.2026-03-29.at.19.46.35.mov

After

Screen.Recording.2026-03-29.at.19.43.00.mov

zojize and others added 2 commits March 29, 2026 16:42
…sion (arnog#2974)

Defer implicit argument deletion until after fraction insertion and
repair orphaned parent references left by deleteAtoms. Add null-safety
throughout model.at() call sites and leftSibling traversals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…Runs

Two bugs caused duplicate ML__caret elements in rendered output:

1. getStyleRuns pushed "first" atoms twice into the same style run
   (missing `continue` after the type check)
2. insertSmartFence case 2.2 didn't filter "first" atoms from
   extractAtoms results, causing root.body and leftright.body to
   share the same first atom object

Also adds a WHY comment for the null cursor fallback in insert().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

TypeError when adding opening parens after closing parens

1 participant