1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-01 03:11:44 +02:00

improve Editor.marks and Editor.nodes abstraction

This commit is contained in:
Ian Storm Taylor
2019-11-29 23:15:08 -05:00
parent 0da1dd128c
commit 68569f286e
51 changed files with 381 additions and 237 deletions

View File

@@ -173,15 +173,13 @@ const App = () => {
if (event.key === '`' && event.ctrlKey) {
event.preventDefault()
// Determine whether any of the currently selected blocks are code blocks.
const { selection } = editor
const isCode = selection
? Editor.match(editor, selection, { type: 'code' })
: false
const [node] = Editor.nodes(editor, { match: { type: 'code' } })
const isCodeActive = !!node
// Toggle the block type depending on `isCode`.
Editor.setNodes(
editor,
{ type: isCode ? 'paragraph' : 'code' },
{ type: isCodeActive ? 'paragraph' : 'code' },
{ match: 'block' }
)
}