feat(app): implement popover-based editor for inline and block math - #112
Open
Carter907 wants to merge 24 commits into
Open
feat(app): implement popover-based editor for inline and block math#112Carter907 wants to merge 24 commits into
Carter907 wants to merge 24 commits into
Conversation
Carter907
force-pushed
the
feat/math-editor-popover
branch
2 times, most recently
from
July 14, 2026 03:28
a960977 to
5bfdaaf
Compare
Carter907
marked this pull request as ready for review
July 14, 2026 03:39
Carter907
marked this pull request as draft
July 15, 2026 02:11
Carter907
marked this pull request as ready for review
July 15, 2026 15:28
Contributor
Author
| // When math-field loses focus, MathLive visually hides the menu but leaves its internal state open. | ||
| // Force a clean reset by programmatically clicking its Scrim background, | ||
| // but only if focus actually left the math-field (not just a temporary blur from clicking the menu toggle). | ||
| const menuToggle = el.shadowRoot.querySelector( |
Collaborator
There was a problem hiding this comment.
What does the menu toggle do. When testing in the browser it doesn't seem to do anything.
Contributor
Author
There was a problem hiding this comment.
Hey this code is for patching up the LaTeX menu, but it's getting pretty ugly and I'm having trouble getting the feature working across browsers, so I just removed it from the math field and added the virtual keyboard instead. Let me know what you think.
Collaborator
There was a problem hiding this comment.
Has this been tested on mobile? Would it work differently?
Contributor
Author
andyrodrigues30
requested changes
Jul 17, 2026
…s, and rendering fixes Signed-off-by: Carter <speers.carter@gmail.com>
Signed-off-by: Carter <speers.carter@gmail.com>
Transition math node editing to a popover-based model to resolve focus conflicts, math-field collapsing, and keyboard event bubbling issues between MathLive and Lexical. - Render static equation previews using KaTeX. - Embed the active math-field editor within a Popover. - Handle click/focus outside events carefully using isTargetMathLive to prevent popover dismissal when interacting with MathLive overlays. - Synchronize popover open state with Lexical node selection and properly return focus to Lexical on close. - Release static MathLive focus references on adapter unmount. - Keep the math-field menu toggle button visible when open. Signed-off-by: Carter <speers.carter@gmail.com>
…n logic Signed-off-by: Carter <speers.carter@gmail.com>
Signed-off-by: Carter <speers.carter@gmail.com>
…stener Signed-off-by: Carter <speers.carter@gmail.com>
This commit introduces two major bug fixes for the MathLive integration within Lexical: 1. Submenu Crash Fix: MathLive throws an unhandled exception if it receives a click on a submenu that is already open. Added a capture-phase interceptor in MathView to block these clicks before MathLive receives them. 2. Singleton Scrim Rescue: When Lexical unmounts the math-field (e.g., clicking outside), MathLive's singleton 'Scrim' gets orphaned. The next time a menu is opened, MathLive calls showPopover on a disconnected element, crashing the editor. A monkey patch for HTMLElement.prototype.showPopover now rescues this orphaned Scrim by locating the newly active math-field and appending it to its shadow DOM. AGENTS.md was also updated to document these exact workarounds.
This commit introduces architectural improvements to the math plugin: 1. Lazy Loading: MathView is now dynamically imported via React.lazy() inside MathNode, ensuring katex and popover dependencies are code-split and only downloaded when a math block actually renders. 2. Lazy Loading Flicker Fix: Fixed a 1-frame visual loading flicker in MathFieldAdapter by using a global flag to skip asynchronous resolution once MathLive is downloaded. 3. Patch Extraction: Moved all ugly global DOM workarounds (showPopover monkey patch, capture-phase submenu interceptor) out of MathView.tsx and into a standalone MathLivePatches.ts file. 4. Blur Logic Fix: Wrapped the onChange callback in a ref to prevent effect teardowns from triggering el.blur() on every keystroke, which previously stole focus. 5. Value Hydration: Initialized lastEmittedValue to null so the math-field successfully hydrates its initial value on mount. 6. Clean Focus Out: Ensured MathLive resets its internal state completely when losing focus by programmatically clicking its Scrim.
This commit introduces architectural improvements to the math plugin: 1. Lazy Loading: MathView is now dynamically imported via React.lazy() inside MathNode, ensuring katex and popover dependencies are code-split and only downloaded when a math block actually renders. 2. Lazy Loading Flicker Fix: Fixed a 1-frame visual loading flicker in MathFieldAdapter by using a global flag to skip asynchronous resolution once MathLive is downloaded. 3. Patch Extraction: Moved all ugly global DOM workarounds (showPopover monkey patch, capture-phase submenu interceptor) out of MathView.tsx and into a standalone MathLivePatches.ts file. 4. Blur Logic Fix: Wrapped the onChange callback in a ref to prevent effect teardowns from triggering el.blur() on every keystroke, which previously stole focus. 5. Value Hydration: Initialized lastEmittedValue to null so the math-field successfully hydrates its initial value on mount. 6. Clean Focus Out: Ensured MathLive resets its internal state completely when losing focus by programmatically clicking its Scrim.
Replaced text placeholder with SVG icon to match block nodes. Added dashed border and refined conditional padding to reduce height layout shifts. Signed-off-by: Carter <speers.carter@gmail.com>
Signed-off-by: Carter <speers.carter@gmail.com>
Decouples the MathView popover from automatic Lexical selection state, allowing users to drag-select across math blocks without forcefully taking focus. Opening the popover now requires an explicit click or Enter key press. Signed-off-by: Carter <speers.carter@gmail.com>
Signed-off-by: Carter <speers.carter@gmail.com>
Signed-off-by: Carter <speers.carter@gmail.com>
Sets math-virtual-keyboard-policy to manual and ensures programmatic focus on the math-field during the toggle button onClick event. This fixes an issue on mobile devices where the keyboard would refuse to display because the mathfield lacked a trusted user focus gesture. Signed-off-by: Carter <speers.carter@gmail.com>
Carter907
force-pushed
the
feat/math-editor-popover
branch
from
July 18, 2026 20:48
e6318a3 to
ff1a2eb
Compare
Changes the fixed height (h-) to a minimum height (min-h-) on the main inner container of the contribute flow. This ensures the background and layout fully encapsulate the content when it overflows vertically. Signed-off-by: Carter <speers.carter@gmail.com>
Carter907
force-pushed
the
feat/math-editor-popover
branch
from
July 18, 2026 21:38
2fe415c to
b263652
Compare
Signed-off-by: Carter <speers.carter@gmail.com>
Signed-off-by: Carter <speers.carter@gmail.com>
Signed-off-by: Carter <speers.carter@gmail.com>
andyrodrigues30
approved these changes
Jul 22, 2026
Collaborator
|
@tonylam0 - I have reviewed but would like you to have a look too |
Contributor
Author
|
This branch still has some bugs which were addressed in #187 |
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.



Summary
Type of change
Verification
pnpm -r typecheckpassespnpm -r buildpassescloses #111