Skip to content

Math format: seed LaTeX input from the current selection#79052

Merged
jasmussen merged 4 commits into
trunkfrom
try/inline-math-copy
Jun 10, 2026
Merged

Math format: seed LaTeX input from the current selection#79052
jasmussen merged 4 commits into
trunkfrom
try/inline-math-copy

Conversation

@jasmussen

Copy link
Copy Markdown
Contributor

What?

Fixes #73035.

The Math inline format previously ignored the current selection and opened an empty popover. This PR changes it so a selection transfers.

state

Why?

It's a small fix that feels nice and less destructive.

Testing Instructions

Type out latex in a paragraph, select it, then choose the inline math format. The formula should transfer.

Use of AI Tools

Claude Opus 4.8.

@jasmussen jasmussen self-assigned this Jun 9, 2026
@jasmussen jasmussen requested a review from ellatrix as a code owner June 9, 2026 13:22
@jasmussen jasmussen added [Type] Enhancement A suggestion for improvement. [Block] Math labels Jun 9, 2026
@github-actions github-actions Bot added the [Package] Format library /packages/format-library label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jasmussen <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: Mamaduka <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Size Change: +68 B (0%)

Total Size: 8.46 MB

📦 View Changed
Filename Size Change
build/scripts/format-library/index.min.js 30.8 kB +68 B (+0.22%)

compressed-size-action

@Mamaduka

Mamaduka commented Jun 9, 2026

Copy link
Copy Markdown
Member

Interesting case, it took me a moment to figure out how to paste LaTex without creating a block 😄

UX, question: What should happen if you click the toolbar button when an active math format is selected? Currently, clears the format, though that's not apparent from the label button. Should we be doing that, or should we just let the user remove the format via a popover?

@ellatrix ellatrix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice @jasmussen!

@ellatrix

ellatrix commented Jun 9, 2026

Copy link
Copy Markdown
Member

UX, question: What should happen if you click the toolbar button when an active math format is selected? Currently, clears the format, though that's not apparent from the label button. Should we be doing that, or should we just let the user remove the format via a popover?

I guess it should revert to the LaTeX representation so that if you click the button twice, you end up in exactly the same state.

@Mamaduka

Mamaduka commented Jun 9, 2026

Copy link
Copy Markdown
Member

Currently, it will remove the active format, which can be unexpected. I think onClick here needs a couple more guards.

Screencast

CleanShot.2026-06-09.at.20.01.01.mp4

jasmussen and others added 3 commits June 10, 2026 08:48
The Math inline format previously ignored the current selection and
opened an empty popover. Like other inline formats, it should act on a
selection: when text is selected, use it as the initial LaTeX, render it
immediately, and replace the selection with the math object.

Invalid expressions are inserted unrendered with the text prefilled so
they can be corrected in the popover.

Fixes #73035.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Clicking the toolbar button while a math object is active now reverts it
to the LaTeX text it was created from, so clicking twice round-trips to
the original state. Previously the active object was replaced
unexpectedly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@jasmussen jasmussen force-pushed the try/inline-math-copy branch from ee77716 to e3ad6a2 Compare June 10, 2026 06:57
@jasmussen

Copy link
Copy Markdown
Contributor Author

Thanks for the green light, and for the fantastic feedback. I fixed the conflicts, and added a change that should address the feedback:

state

@ellatrix

Copy link
Copy Markdown
Member

Looks good! Should we keep the text selected after removing the format?

When clicking the button reverts an active math object to its LaTeX
source, keep that text selected rather than collapsing to a caret, so it
can be edited or re-marked as math right away.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@jasmussen

Copy link
Copy Markdown
Contributor Author

Good call, gave it a shot.
state

@github-actions

Copy link
Copy Markdown

Flaky tests detected in bd0e902.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27259980168
📝 Reported issues:

@ellatrix

Copy link
Copy Markdown
Member

Looks good to me, go for it 🙂

@jasmussen jasmussen merged commit a2ed6c2 into trunk Jun 10, 2026
49 of 50 checks passed
@jasmussen jasmussen deleted the try/inline-math-copy branch June 10, 2026 09:16
@github-actions github-actions Bot added this to the Gutenberg 23.5 milestone Jun 10, 2026
@Mamaduka

Copy link
Copy Markdown
Member

Sorry, I was experimenting with something, but didn't make it in time. Here's a small follow-up - #79081.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Math [Package] Format library /packages/format-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Math inline format: if you make a selection of latex first, use that

3 participants