Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
I don't think that this makes sense as a default given that it breaks backwards compatibility but it could be an option to RichTextExtension or its own extension
|
I support the idea of adding this option to the extension. Besides, why not do this for any other formats? A long time ago, I created a workaround like this for my plugin editor.registerCommand(
INSERT_PARAGRAPH_COMMAND,
() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.format = 0;
}
return false;
},
COMMAND_PRIORITY_HIGH
) |
|
Also I'm not sure that it need to handle clicking or right/left keys to exit the format. Are there any editors with a similar UX? |
|
These aren’t code nodes, they’re just text nodes with code formatting. Not really any different than bold or italic. Trying to make it behave differently is not backwards compatible. Offering an extension or configuration of the RichTextExtension to alter this behavior makes sense, but just changing how it works for everyone with no opt-in doesn’t really make sense. |
…rmatting in shortcuts (#8381)
…] Refactor: make runtime style updates CSP-safe (#8372)
…ordering for DOMRenderExtension overrides and add $decorateDOM (#8368)
…sertNodeToNearestRootAtCaret edge cases (#8384)
…rag-and-drop within the same block (#8373) Co-authored-by: Claude <noreply@anthropic.com>
…opt-in format escape at text node boundaries
…opt-in format escape at text node boundaries
etrepum
left a comment
There was a problem hiding this comment.
After looking a bit more closely at this I think the configuration should probably be more flexible since you may want to have different triggers for different keys. For example the current @lexical/rich-text has a $resetCapitalization which is basically this but for ['lowercase', 'uppercase', 'capitalize'] and ['enter', 'space', 'tab']. We could embed this into the existing RichTextExtension since that functionality is already mostly there.
Possibly a way to configure this would be something like:
export interface TriggerConfig {
[K in EscapeFormatTrigger]:? boolean;
}
export interface EscapeFormatTriggerConfig {
[K in TextFormatType]?: null | TriggerConfig;
}escapeFormatTriggers: {
lowercase: {enter: true, space: true, tab: true},
uppercase: {enter: true, space: true, tab: true},
capitalize: {enter: true, space: true, tab: true},
code: {enter: true},
},
This structure would also be suitable for a straightforward mergeConfig implementation where overrides can turn anything on or off.
|
Thanks for the feedback! Just want to make sure I'm on the same page before I start working on this:
One thing I'd prefer keeping this as a standalone extension rather than putting it inside RichTextExtension. Feels like it makes more sense as something you opt into. But if you'd rather have it there, I'm open to that too. Let me know if I'm understanding this right! |
|
It would be fine to put it in RichTextExtension because it overlaps with the $resetCapitalization code, the opt-in would simply be configuring it differently. If you want to keep it separate for now, that’s fine too, but it will probably end up in RichTextExtension eventually one way or another. |
…opt-in format escape at text node boundaries (facebook#8383) Co-authored-by: Sergey Gorbachev <grbchv.s@gmail.com> Co-authored-by: Sherry <potatowagon@meta.com> Co-authored-by: Bob Ippolito <bob@redivi.com> Co-authored-by: Agyei Holy <agyeiholy978@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
Description
EscapeFormatAtBoundaryExtensionin@lexical/extensionthat clears inline code formatting when the cursor is at the boundary of a code-formatted text node with no adjacent siblingtriggers('enter','click','arrow')registerEscapeFormatAtBoundaryfor non-extension usageregisterRichTextto preserve backwards compatibilityCloses #4936
Test plan
Before
Screen.Recording.2026-04-22.at.11.28.07.PM.mov
After
Screen.Recording.2026-04-22.at.8.57.42.PM.mov