Skip to content

[lexical] Feature: add commands for beforeinput, input, compositionstart/end events#7964

Merged
etrepum merged 3 commits intofacebook:mainfrom
james-atticus:use-commands-for-input-events
Nov 6, 2025
Merged

[lexical] Feature: add commands for beforeinput, input, compositionstart/end events#7964
etrepum merged 3 commits intofacebook:mainfrom
james-atticus:use-commands-for-input-events

Conversation

@james-atticus
Copy link
Copy Markdown
Contributor

Description

In order to any sort of track changes/suggestion mode feature, consumers need to be able to intercept/override events that mutate editor state. This is already the case for many operations, but not for input and composition events.

This PR adds commands for beforeinput, input, compositionstart and compositionend. The existing functions for these events have been repurposed into command handlers which are registered when creating a new editor instance.

Test plan

One test was relying on editor._commands being empty by default; updated that test to be slightly more targeted.

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Nov 6, 2025 5:47pm
lexical-playground Ready Ready Preview Comment Nov 6, 2025 5:47pm

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 31, 2025
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

I think this is probably right and I'll give it a closer look later but one thing to think about here is that with nested editors there's this weird "feature" where commands from one editor can bubble to the parent editor if no handler (at any priority) returns true. A thorough review to make sure that the way these events are handled in nested editor situations in the same way with the old method and this new command based method are equivalent.

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Oct 31, 2025
etrepum
etrepum previously approved these changes Nov 6, 2025
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

This looks good to me, since all of these new command listeners are unconditionally returning true and the manner in which the DOM events are being listened to doesn't change there doesn't seem to be any risk of different behavior for editor propagation

Merged via the queue into facebook:main with commit bb1f905 Nov 6, 2025
39 checks passed
@etrepum etrepum mentioned this pull request Dec 10, 2025
@code-alexander
Copy link
Copy Markdown

This broke KEY_DOWN_COMMAND for me. Was able to resolve it by changing the priority to COMMAND_PRIORITY_HIGH instead of COMMAND_PRIORITY_EDITOR.

Sharing in case it's helpful.

@mdmahendri
Copy link
Copy Markdown

thanks @code-alexander , for me COMMAND_PRIORITY_NORMAL is enough
I think this is somehow related to the PR on LexicalEditor.ts#665, where keydown and beforeinput in registerDefaultCommandHandlers use COMMAND_PRIORITY_EDITOR

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants