1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-01 19:22:35 +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

@@ -26,13 +26,11 @@ const App = () => {
if (event.key === '`' && event.ctrlKey) {
event.preventDefault()
const { selection } = editor
const isCode = selection
? Editor.match(editor, selection, { type: 'code' })
: false
const [node] = Editor.nodes(editor, { match: { type: 'code' } })
const isCodeActive = !!node
Editor.setNodes(
editor,
{ type: isCode ? 'paragraph' : 'code' },
{ type: isCodeActive ? 'paragraph' : 'code' },
{ match: 'block' }
)
}
@@ -70,14 +68,11 @@ const App = () => {
// When "`" is pressed, keep our existing code block logic.
case '`': {
event.preventDefault()
const { selection } = editor
const isCode = selection
? Editor.match(editor, selection, { type: 'code' })
: false
const [node] = Editor.nodes(editor, { match: { type: 'code' } })
const isCodeActive = !!node
Editor.setNodes(
editor,
{ type: isCode ? null : 'code' },
{ type: isCodeActive ? null : 'code' },
{ match: 'block' }
)
break
@@ -147,14 +142,11 @@ const App = () => {
switch (event.key) {
case '`': {
event.preventDefault()
const { selection } = editor
const isCode = selection
? Editor.match(editor, selection, { type: 'code' })
: false
const [node] = Editor.nodes(editor, { match: { type: 'code' } })
const isCodeActive = !!node
Editor.setNodes(
editor,
{ type: isCode ? null : 'code' },
{ type: isCodeActive ? null : 'code' },
{ match: 'block' }
)
break