Skip to content

Commit

Permalink
Add auto soft line break
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jan 30, 2024
1 parent d5fe426 commit 31a70d6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions frontend/src/components/editor/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@ function Preview() {
useEffect(() => {
if (!editorStore.doc) return;

setContent(editorStore.doc?.getRoot().content?.toString() || "");
const updatePreviewContent = () => {
const editorText = editorStore.doc?.getRoot().content?.toString() || "";
// Add soft line break
setContent(
editorText
.split("\n")
.map((line) => line + " ")
.join("\n")
);
};

updatePreviewContent();

const unsubsribe = editorStore.doc.subscribe("$.content", () => {
setContent(editorStore.doc?.getRoot().content.toString() as string);
updatePreviewContent();
});

return () => {
Expand Down

0 comments on commit 31a70d6

Please sign in to comment.