1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-10 17:24:02 +02:00

fix: isBlockActive should use Array.from() (#4662)

* fix: isBlockActive should use Array.from()

The richtext.tsx example `isBlockActive`  was not working for me in my environtment because `Editor.nodes` returns a Generator, not an Array. So `isBlockActive` always returned false. Wrapping it in `Array.from` fixes the example.

* run prettier

Co-authored-by: Dan Tello <dtello@medallia.com>
This commit is contained in:
Dan Tello
2021-12-17 07:34:18 -05:00
committed by GitHub
parent ab62da2064
commit 65708358bb

View File

@@ -96,11 +96,13 @@ const isBlockActive = (editor, format) => {
const { selection } = editor const { selection } = editor
if (!selection) return false if (!selection) return false
const [match] = Editor.nodes(editor, { const [match] = Array.from(
at: Editor.unhangRange(editor, selection), Editor.nodes(editor, {
match: n => at: Editor.unhangRange(editor, selection),
!Editor.isEditor(n) && SlateElement.isElement(n) && n.type === format, match: n =>
}) !Editor.isEditor(n) && SlateElement.isElement(n) && n.type === format,
})
)
return !!match return !!match
} }