1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 02:19:52 +02:00

Fix: Ensure block transformation works in the example (#5803)

I noticed that the current example for toggling a code block using the backtick (`) key doesn't work as expected. The issue occurs because `Editor.nodes()` can return text nodes instead of block elements, causing`Transforms.setNodes()` to fail.

To fix this, I added an extra check using `Element.isElement(n)`, ensuring that only block elements are transformed.
This commit is contained in:
aberllin
2025-02-10 02:51:48 +01:00
committed by GitHub
parent a61baa99bd
commit 7a8ab18c52

View File

@@ -39,7 +39,7 @@ const App = () => {
Transforms.setNodes(
editor,
{ type: match ? 'paragraph' : 'code' },
{ match: n => Editor.isBlock(editor, n) }
{ match: n => Element.isElement(n) && Editor.isBlock(editor, n) }
)
}
}}
@@ -90,7 +90,7 @@ const App = () => {
Transforms.setNodes(
editor,
{ type: match ? 'paragraph' : 'code' },
{ match: n => Editor.isBlock(editor, n) }
{ match: n => Element.isElement(n) && Editor.isBlock(editor, n) }
)
break
}
@@ -178,7 +178,7 @@ const App = () => {
Transforms.setNodes(
editor,
{ type: match ? null : 'code' },
{ match: n => Editor.isBlock(editor, n) }
{ match: n => Element.isElement(n) && Editor.isBlock(editor, n) }
)
break
}