[lexical-code-core][lexical-playground] Feature: Create paragraph around the code node when navigating with the arrow keys#8393
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
e91d66c to
bd11e8c
Compare
|
This should probably be a configuration option built into a signal for registration because it's not always desired behavior, e.g. when you have the playground in markdown or html mode you do not want to be able to exit that CodeNode at all. |
bd11e8c to
f94fdb0
Compare
Currently, the playground removes any non-CodeNode elements in Markdown/HTML mode, so I didn't add this option initially. But overall, it wouldn't hurt to have this option anyway — the only question is, should this behavior be the default? I would enable it by default because CodeExtension is a new extension and the current feature will not change the behavior of CodeNode unless you enable the extension |
|
The current feature is a direct copy of CollapsibleContainer. I also thought it might be a good idea to add similar key handling for table cells, but perhaps we should move the current handlers into generic functions in |
|
Moving shared code to |
|
Collapsible doesn't have to have any compatibility considerations because it's not a published package, it just lives in the playground |
c611d53 to
6fc33c1
Compare
etrepum
left a comment
There was a problem hiding this comment.
Overall this looks good, but it doesn't seem to work with an empty code block
6e85684 to
2aa1b6e
Compare
potatowagon
left a comment
There was a problem hiding this comment.
Review — Create Paragraph Around Code Node with Arrow Keys
Assessment: Looks good to land ✅
What I verified:
-
Feature scope: Adds arrow-key escape behavior for code blocks — pressing up/left at the start or down/right at the end of a code block creates a new paragraph to allow adding content before/after. Uses the existing
$onEscapeUp/$onEscapeDownutilities from@lexical/utils. -
Implementation: The
escapeWithArrowsparameter is added toregisterCodeIndentationas an opt-in boolean. The handlers register atCOMMAND_PRIORITY_LOWso they run before$handleShiftLines. The fix also correctly changes the return value in$handleShiftLinesfromtruetofalsewhen at a boundary (so the command continues propagating to the escape handlers). -
Edge case handling: Alt+arrow is excluded (for line-shift operations). The sibling-null check ensures paragraphs are only created when the code block is at the document boundary.
-
CI status: Full CI suite green (42 checks including all e2e tests across all platforms).
-
Risk: Opt-in behavior, no change to default code block navigation. Existing tests still pass.
— via Navi on behalf of potatowagon
Description
lexical-utils
Handlers
$onEscapeDownand$onEscapeUphave been added to create paragraphs when the cursor is at the end of an element and that element is the last one in the root. Use these handlers for arrow key commands.lexical-code-core
The
CodeIndentExtensionnow includes anescapeWithArrowsoption (default: false), which improves keyboard usability. When this option is enabled, if CodeNode is the terminal node and the cursor is at the end of the text, pressing the arrow keys will create a new paragraph and move the cursor to itCloses #7912
Test plan
Before
Insert relevant screenshots/recordings/automated-tests
After
Insert relevant screenshots/recordings/automated-tests