mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-11-20 21:23:37 +03:00
Fixes #15643 ## Problem In Firefox, pressing Ctrl+A in the LaTeX editor popup (inline equation or equation block) selects the formula for a moment, then the selection disappears. After that, typing has no effect. Chromium works. Two things go wrong on Firefox: 1. **The select-all is dropped.** Firefox places the native select-all range on the inline root rather than on text nodes. The editor's range sync (`RangeBinding._onNativeSelectionChanged`) removes ranges whose endpoints aren't inside a `v-text`. Table and database cells already handle `Mod+A` themselves with `inlineEditor.selectAll()`, but the popup didn't. 2. **Input over a full selection goes to the end.** Even with a proper selection, Firefox's `beforeinput` `getTargetRanges()` starts at the inline root (for example `DIV[data-v-root]@2`, just before the `v-line`). That point resolves to the end of the text. `EventService._onBeforeInput` then lets the target range replace the native one, so `a+b=c` + `x` became `a+b=cx` instead of `x`, and Backspace did nothing. ## Fix - `LatexEditorMenu` handles `Mod+A` with `inlineEditor.selectAll()` and stops the event, the same way `table-cell.ts` and the database cell renderers do. - `EventService._onBeforeInput` uses the target range only when the native selection is collapsed. A non-collapsed selection is exactly what the input replaces. Target ranges are still used for collapsed selections, e.g. word deletion and the embed/empty-line case above it. ## Testing - New unit test in `event-beforeinput.unit.spec.ts`. It selects the whole text and feeds a Firefox-shaped target range that starts at the inline root. - Without the `event.ts` change it fails with `expected 'a+b=cx' to be 'x'`, the same result as in Firefox. - With the change it passes. - `yarn vitest run` in `blocksuite/framework/std`: 12 files, 102 tests pass. - `oxlint --deny-warnings` and `oxfmt --check` pass on the changed files, and `tsc -b blocksuite/affine/inlines/latex/tsconfig.json` passes. - I couldn't run a patched build in Firefox. Instead I checked both changes in Firefox and Chromium (Playwright, headless) on app.affine.pro, using a guest doc and injecting equivalent handlers into the page. With both changes, Ctrl+A in the inline equation editor keeps `a+b=c` selected, typing `x` gives `x`, and Backspace clears it. Without them, Firefox shows the bug described in the issue. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Select-all now works in the LaTeX editor with the platform’s standard keyboard shortcut. * Fixed text replacement after selecting all, including cases where the browser reports the selection from the start of the editor. <!-- end of auto-generated comment: release notes by coderabbit.ai -->