From e2585b8489b96efb2b4f830f4e41b7d5767fe828 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Sat, 4 May 2024 13:20:04 +0300 Subject: [PATCH] fix: allow focusing an empty editor Fixes https://github.com/mdx-editor/editor/issues/446 --- src/examples/basics.tsx | 10 ++++++++++ src/plugins/core/index.ts | 6 ++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/examples/basics.tsx b/src/examples/basics.tsx index f4638f39..1116911d 100644 --- a/src/examples/basics.tsx +++ b/src/examples/basics.tsx @@ -45,6 +45,16 @@ export function Bare() { ) } +export function FocusEmpty() { + const ref = React.useRef(null) + return ( + <> + + + + ) +} + export function Placeholder() { return ( <> diff --git a/src/plugins/core/index.ts b/src/plugins/core/index.ts index 90fe2620..0caf0104 100644 --- a/src/plugins/core/index.ts +++ b/src/plugins/core/index.ts @@ -898,10 +898,8 @@ export const corePlugin = realmPlugin<{ }) newEditor.update(() => { - const markdown = params?.initialMarkdown.trim() - if (markdown) { - tryImportingMarkdown(r, $getRoot(), markdown) - } + const markdown = params?.initialMarkdown.trim() ?? '' + tryImportingMarkdown(r, $getRoot(), markdown) const autoFocusValue = params?.autoFocus if (autoFocusValue) {