-
|
I've tried to create a normalizeNode plugin that merges TText siblings into one (my TText nodes does not have any other props that My plugin calls replaceNodes with the new children array that has merged TText nodes. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Slate already handles this automatically! The built-in Why you're getting path errors:
"overrides": {
"slate": "0.118.0",
"slate-dom": "0.117.4",
"slate-react": "0.117.1"
}If you still need custom merging, use .overrideEditor(({ editor, tf: { normalizeNode } }) => ({
transforms: {
normalizeNode([node, path]) {
if (ElementApi.isElement(node)) {
for (let i = node.children.length - 1; i > 0; i--) {
const child = node.children[i];
const prev = node.children[i - 1];
if (TextApi.isText(child) && TextApi.isText(prev)) {
editor.tf.mergeNodes({ at: [...path, i] });
return; // MUST return after any transform
}
}
}
normalizeNode([node, path]);
},
},
}))
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=udecode%2Fplate).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=udecode%2Fplate).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=udecode%2Fplate#message_id=9381367e-746a-4de3-bb1c-9613160ed801) [](https://github.dosu.com/udecode/plate?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=udecode%2Fplate) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=udecode%2Fplate) |
Beta Was this translation helpful? Give feedback.
Slate already handles this automatically! The built-in
normalizeNode()merges adjacent text nodes with matching properties during normalization—you likely don't need a custom plugin.Why you're getting path errors:
Paths become stale after transforms — When you call
replaceNodesinnormalizeNode, all paths become invalid. You mustreturnimmediately after any transform and not call other methods likeeditor.api.blocks().Possible Slate version conflicts — This is the #1 cause of path errors in Plate. Add overrides to your package.json:
If you still need custom merging, use
mergeNodesinstead…