1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-21 13:51:59 +02:00

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

* 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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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