lexical
lexical copied to clipboard
Bug: EquationNode click yields no selection, and empty-input Backspace leaves the node behind
Lexical version: 0.44
Steps To Reproduce
(A) Selection on click
- In the playground, insert an Equation (block mode) so the editor contains only the equation as the sole root child (delete the surrounding paragraphs if needed).
- Click the rendered KaTeX once.
- Inspect
$getSelection()(TreeView panel showsselection: null).
(B) Empty-input Backspace doesn't remove the equation
- Insert any Equation. Double-click it to open the inline LaTeX editor.
- Select all and delete the LaTeX so the input value is empty.
- Press Backspace once more.
- The host EquationNode is still in the document with an empty equation.
Link to code example: https://playground.lexical.dev/
https://github.com/user-attachments/assets/aa321c53-ab91-416f-92b1-5c3c58eaf340
The current behavior
- (A) A single click on the rendered equation does not turn into a
NodeSelection. Downstream commands (Backspace, copy, arrow navigation) have no selection to act on. With no surrounding paragraph, the user is stuck — there's no caret to type into and no selection to drive a delete. - (B) When the LaTeX input is already empty, an extra Backspace is a no-op (browser default for an empty input). The host EquationNode persists in the editor with an empty equation, and the user has no obvious way out.
Same EquationNode behavior for inline equations as well (clicking the inline equation does not create a NodeSelection).
The expected behavior
- (A) Clicking the rendered equation should set a
NodeSelectionon the EquationNode — same pattern asImageNode/PollNodeetc. The visible selection outline (.editor-equation.focused) should render. Downstream commands (Backspace to delete, copy, Enter to insert a paragraph after) should then work normally. - (B) Pressing Backspace inside an already-empty LaTeX input should remove the host EquationNode and place the caret at the end of the previous sibling — or, if the equation has no previous sibling, replace it with an empty paragraph so the editor stays usable.
Impact of fix
- A block equation that ends up as the sole root child (e.g. via paste, conversion, or undoing surrounding content) leaves the editor unusable: no caret, no selection, no way to delete. Reload is the only escape.
- Inconsistent UX vs other DecoratorNodes (Image, Poll) that do create a NodeSelection on click.
- The empty-input Backspace dead end traps users in a state they didn't intend to reach.