[lexical] Feature: COMMAND_PRIORITY_BEFORE_* priorities for last-registered-called-first order#8375
Merged
etrepum merged 7 commits intofacebook:mainfrom Apr 21, 2026
Merged
Conversation
…ow last-registered-called-first
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
zurfyx
approved these changes
Apr 20, 2026
COMMAND_PRIORITY_BEFORE_* priorities for last-registered-called-first order
levensta
pushed a commit
to levensta/lexical
that referenced
this pull request
Apr 22, 2026
…gistered-called-first order (facebook#8375)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Command listeners are now called in the following order until a listener returns
true:COMMAND_PRIORITY_BEFORE_${priority}listeners, most recently registered firstCOMMAND_PRIORITY_${priority}listeners, in registration orderThis PR adds support for adding to "both ends" of the listener collection with a deque (double ended queue) type data structure with the following new priorities:
COMMAND_PRIORITY_BEFORE_EDITORCOMMAND_PRIORITY_BEFORE_LOWCOMMAND_PRIORITY_BEFORE_NORMALCOMMAND_PRIORITY_BEFORE_HIGHCOMMAND_PRIORITY_BEFORE_CRITICALGenerally these new before priorities can be used in place of their respective legacy priority and you will get the desired behavior. There is little reason to use the legacy priorities except to support legacy code that may have subtle ordering dependencies.
New Commands priorities and ordering docs
The original
editor.dispatchCommandordering (highest priority first, then first registered) was counter-productive, a more useful order is highest priority first, then last registered (highest index first). The ideal ordering is almost always for last-registered to be called first.It was so rarely useful in fact that changing the order globally only broke a single e2e test where the
@lexical/rich-texthandler forKEY_TAB_COMMAND,KEY_ENTER_COMMANDandKEY_SPACE_COMMANDto reset capitalization (the 'lowercase', 'uppercase', and 'capitalize' formats) was expected to be called even though it is the lowest editor priority. This has been left as-is since we are making an additive change and the existing priorities are not reversed.Priorities of all existing command registrations have not changed, so this new ordering should not be a breaking change.
Test plan
New unit tests to confirm expected call order and internal representation.