1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-31 06:18:01 +00:00

LFのみ残り続ける問題を修正

This commit is contained in:
Nebel 2022-08-29 12:24:40 +09:00
parent 887eafef4d
commit 3ea90fbd06

View file

@ -1,4 +1,5 @@
import { import {
$createLineBreakNode,
$createParagraphNode, $createParagraphNode,
$createTextNode, $createTextNode,
$getRoot, $getRoot,
@ -25,8 +26,11 @@ export default (props: {
const root = $getRoot(); const root = $getRoot();
if (root.getFirstChild()) return; if (root.getFirstChild()) return;
const paragraphNode = $createParagraphNode(); const paragraphNode = $createParagraphNode();
const textNode = $createTextNode(props.text); const text = props.text
paragraphNode.append(textNode); .split("\n")
.flatMap((line) => [$createTextNode(line), $createLineBreakNode()])
.slice(0, -1);
paragraphNode.append(...text);
root.append(paragraphNode); root.append(paragraphNode);
}; };
onCleanup(registerPlainText(editor, initialEditorState)); onCleanup(registerPlainText(editor, initialEditorState));