feat(editor): improve latex editing support (#14924)

## Summary
- support converting selected text into inline LaTeX equations
- support turning text blocks into LaTeX equation blocks
- add equation entries to editor toolbars while keeping inline equation
with text formatting actions

## Tests
- yarn tsc -b blocksuite/affine/inlines/latex/tsconfig.json
blocksuite/affine/blocks/note/tsconfig.json
blocksuite/affine/blocks/root/tsconfig.json
blocksuite/affine/rich-text/tsconfig.json
blocksuite/affine/widgets/keyboard-toolbar/tsconfig.json --pretty false
- git diff --check origin/canary...HEAD

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
  * Equation block support with conversion from existing blocks.
  * Inline LaTeX insertion added to the inline formatting toolbar.
* Equation action added to the keyboard toolbar; Equation blocks
searchable via math/equation/latex aliases.

* **Improvements**
* Inline LaTeX editor opens and syncs more reliably; selection/convert
flow preserves distinct LaTeX values when converting in reverse order.

* **Tests**
  * New e2e tests for inline LaTeX conversions and value preservation.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/toeverything/AFFiNE/pull/14924)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Jachin
2026-05-14 11:56:54 +08:00
committed by GitHub
parent 7280fe33bc
commit 542da0b347
11 changed files with 249 additions and 39 deletions

View File

@@ -30,6 +30,7 @@
"@blocksuite/affine-gfx-pointer": "workspace:*",
"@blocksuite/affine-gfx-shape": "workspace:*",
"@blocksuite/affine-gfx-text": "workspace:*",
"@blocksuite/affine-inline-latex": "workspace:*",
"@blocksuite/affine-inline-preset": "workspace:*",
"@blocksuite/affine-model": "workspace:*",
"@blocksuite/affine-rich-text": "workspace:*",

View File

@@ -15,6 +15,7 @@ import {
import type { HighlightType } from '@blocksuite/affine-components/highlight-dropdown-menu';
import { toast } from '@blocksuite/affine-components/toast';
import { EditorChevronDown } from '@blocksuite/affine-components/toolbar';
import { insertInlineLatex } from '@blocksuite/affine-inline-latex';
import {
deleteTextCommand,
formatBlockCommand,
@@ -61,6 +62,7 @@ import {
DeleteIcon,
DuplicateIcon,
LinkedPageIcon,
TeXIcon,
} from '@blocksuite/icons/lit';
import {
type BlockComponent,
@@ -199,9 +201,9 @@ const alignActionGroup = {
const inlineTextActionGroup = {
id: 'b.inline-text',
when: ({ chain }) => isFormatSupported(chain).run()[0],
actions: textFormatConfigs.map(
actions: textFormatConfigs.flatMap(
({ id, name, action, activeWhen, icon }, score) => {
return {
const textAction: ToolbarAction = {
id,
icon,
score,
@@ -209,6 +211,28 @@ const inlineTextActionGroup = {
run: ({ host }) => action(host),
active: ({ host }) => activeWhen(host),
};
if (id !== 'underline') {
return [textAction];
}
return [
textAction,
{
id: 'inline-latex',
icon: TeXIcon(),
score: score + 0.5,
tooltip: 'Inline Equation',
run: ({ host }) => {
host.std.command
.chain()
.pipe(getTextSelectionCommand)
.pipe(insertInlineLatex)
.run();
},
active: () => false,
},
];
}
),
} as const satisfies ToolbarActionGroup;

View File

@@ -27,6 +27,7 @@
{ "path": "../../gfx/pointer" },
{ "path": "../../gfx/shape" },
{ "path": "../../gfx/text" },
{ "path": "../../inlines/latex" },
{ "path": "../../inlines/preset" },
{ "path": "../../model" },
{ "path": "../../rich-text" },