From 65708358bb744cfada4c51e93888e254209d2515 Mon Sep 17 00:00:00 2001 From: Dan Tello Date: Fri, 17 Dec 2021 07:34:18 -0500 Subject: [PATCH] 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 --- site/examples/richtext.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/site/examples/richtext.tsx b/site/examples/richtext.tsx index 768e5bf07..02001854a 100644 --- a/site/examples/richtext.tsx +++ b/site/examples/richtext.tsx @@ -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 }