code_block is split into separate nodes on return or enter key #4402
-
DescriptionUsing the CodeBlockKit, anytime return or enter is pressed on the keyboard the node doesn't go to a new line but splits the code block into two individual nodes. Using Reproduction URLNo response Reproduction steps
Plate version49.0.6 Slate React version0.117.1 ScreenshotsLogsBrowsersNo response |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
Hi @calebpitan! I'm Dosu and I’m helping the plate team. The expected behavior is: pressing Enter inside a code block should insert a new line and keep syntax highlighting. Plate handles this by overriding the editor’s insertBreak method in the code block plugin—so Enter never splits the block, and Shift+Enter isn’t treated specially by default. If you’re seeing node splits on Enter and losing highlighting on Shift+Enter, it’s likely due to a plugin misconfiguration, plugin order, or a custom keyboard handler interfering with Plate’s logic. Check that your code block plugin setup matches the docs and includes the withCodeBlock override, and that you’re using the lowlight option for syntax highlighting. Also, make sure you don’t have any custom onKeyDown handlers or external keyboard event listeners that might override Plate’s default behavior. If possible, try isolating the code block plugin in a minimal setup to see if the issue persists—this can help pinpoint if another plugin or handler is causing the conflict. Reference:
To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
None of the suggestions above did anything differently |
Beta Was this translation helpful? Give feedback.
-
I've set break rules in the code block kit to default to line break as the JSDoc comment claims it splits the node by default (which I don't think anyone would consider a sensible default). export const CodeBlockKit = [
CodeBlockPlugin.configure({
node: { component: CodeBlockElement },
rules: {
break: { default: 'lineBreak' },
},
options: { lowlight },
shortcuts: {
toggle: { keys: 'mod+alt+8' },
},
}),
CodeLinePlugin.withComponent(CodeLineElement),
CodeSyntaxPlugin.withComponent(CodeSyntaxLeaf),
] Yet after achieving this, I can't get syntax highlighting to work past the first line. I think this is because only a line break is inserted, all still in the same I've tried to override the |
Beta Was this translation helpful? Give feedback.
-
Could you reproduce it from https://github.com/udecode/plate-template? It seems to work fine in the docs. |
Beta Was this translation helpful? Give feedback.
Actual:
{ text: "const name = 'caleb';", type: 'code_line' },
Expected:
{ children: [{ text: "const name = 'caleb';" }], type: 'code_line' },