From 785a6331158346357916f0a08321e1e809ab1aa8 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Thu, 11 Dec 2025 20:15:53 +0100 Subject: [PATCH] Fix: trim hardbreak only at start and end --- common/src/util/parse.ts | 10 +++++----- web/pages/messages/[channelId].tsx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/util/parse.ts b/common/src/util/parse.ts index 20fd8fb..f0f674a 100644 --- a/common/src/util/parse.ts +++ b/common/src/util/parse.ts @@ -108,18 +108,18 @@ function _cleanDoc(doc: JSONContent) { } // Trim leading/trailing hardBreaks within first and last paragraphs - const trimHardBreaks = (paragraph: JSONContent) => { + const trimHardBreaks = (paragraph: JSONContent, start: boolean, end: boolean) => { if (!paragraph.content) return paragraph; let nodes = [...paragraph.content]; // Remove hardBreaks at the start - while (nodes.length > 0 && nodes[0].type === "hardBreak") { + while (start && nodes.length > 0 && nodes[0].type === "hardBreak") { nodes.shift(); } // Remove hardBreaks at the end - while (nodes.length > 0 && nodes[nodes.length - 1].type === "hardBreak") { + while (end && nodes.length > 0 && nodes[nodes.length - 1].type === "hardBreak") { nodes.pop(); } @@ -127,9 +127,9 @@ function _cleanDoc(doc: JSONContent) { }; if (content.length > 0) { - content[0] = trimHardBreaks(content[0]); + content[0] = trimHardBreaks(content[0], true, false); if (content.length > 1) { - content[content.length - 1] = trimHardBreaks(content[content.length - 1]); + content[content.length - 1] = trimHardBreaks(content[content.length - 1], false, true); } } diff --git a/web/pages/messages/[channelId].tsx b/web/pages/messages/[channelId].tsx index 9f97e66..1374681 100644 --- a/web/pages/messages/[channelId].tsx +++ b/web/pages/messages/[channelId].tsx @@ -185,7 +185,7 @@ export const PrivateChat = (props: { try { const content = cleanDoc(editor.getJSON()) - // console.log('submitting message', JSON.stringify(content)) + // console.log('submitting message\n', JSON.stringify(editor.getJSON()), JSON.stringify(content)) if (editingMessage) { // console.log('editingMessage edit-message', editingMessage) setMessages((prevMessages) =>