From 3ea90fbd06ea430207b6aae47cbfa09f9ce1b614 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Mon, 29 Aug 2022 12:24:40 +0900 Subject: [PATCH] =?UTF-8?q?LF=E3=81=AE=E3=81=BF=E6=AE=8B=E3=82=8A=E7=B6=9A?= =?UTF-8?q?=E3=81=91=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/components/editor.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/components/editor.tsx b/app/src/components/editor.tsx index 57d515f..1fe128c 100644 --- a/app/src/components/editor.tsx +++ b/app/src/components/editor.tsx @@ -1,4 +1,5 @@ import { + $createLineBreakNode, $createParagraphNode, $createTextNode, $getRoot, @@ -25,8 +26,11 @@ export default (props: { const root = $getRoot(); if (root.getFirstChild()) return; const paragraphNode = $createParagraphNode(); - const textNode = $createTextNode(props.text); - paragraphNode.append(textNode); + const text = props.text + .split("\n") + .flatMap((line) => [$createTextNode(line), $createLineBreakNode()]) + .slice(0, -1); + paragraphNode.append(...text); root.append(paragraphNode); }; onCleanup(registerPlainText(editor, initialEditorState));