Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const isFormatActive = (editor, format) => {
const [match] = Editor.nodes(editor, {
match: n => n[format] === true,
mode: 'all',
})
return !!match
}
const isBlockActive = (editor, format) => {
const [match] = Editor.nodes(editor, {
match: n => n.type === format,
})
return !!match
}
editor.deleteBackward = unit => {
const { selection } = editor
if (selection && Range.isCollapsed(selection)) {
const [cell] = Editor.nodes(editor, {
match: n => n.type === 'table-cell',
})
if (cell) {
const [, cellPath] = cell
const start = Editor.start(editor, cellPath)
if (Point.equals(selection.anchor, start)) {
return
}
}
}
deleteBackward(unit)
}
editor.deleteBackward = (...args) => {
const { selection } = editor
if (selection && Range.isCollapsed(selection)) {
const [match] = Editor.nodes(editor, {
match: n => n.type === 'check-list-item',
})
if (match) {
const [, path] = match
const start = Editor.start(editor, path)
if (Point.equals(selection.anchor, start)) {
Transforms.setNodes(
editor,
{ type: 'paragraph' },
{ match: n => n.type === 'check-list-item' }
)
return
}
}
export function isMarkActive(editor: Editor, mark: string) {
const [match] = SlateEditor.nodes(editor, {
match(node) {
return node[mark]
}
})
return Boolean(match)
}