Skip to content

Commit 785a633

Browse files
committed
Fix: trim hardbreak only at start and end
1 parent 57beefb commit 785a633

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

common/src/util/parse.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,28 @@ function _cleanDoc(doc: JSONContent) {
108108
}
109109

110110
// Trim leading/trailing hardBreaks within first and last paragraphs
111-
const trimHardBreaks = (paragraph: JSONContent) => {
111+
const trimHardBreaks = (paragraph: JSONContent, start: boolean, end: boolean) => {
112112
if (!paragraph.content) return paragraph;
113113

114114
let nodes = [...paragraph.content];
115115

116116
// Remove hardBreaks at the start
117-
while (nodes.length > 0 && nodes[0].type === "hardBreak") {
117+
while (start && nodes.length > 0 && nodes[0].type === "hardBreak") {
118118
nodes.shift();
119119
}
120120

121121
// Remove hardBreaks at the end
122-
while (nodes.length > 0 && nodes[nodes.length - 1].type === "hardBreak") {
122+
while (end && nodes.length > 0 && nodes[nodes.length - 1].type === "hardBreak") {
123123
nodes.pop();
124124
}
125125

126126
return { ...paragraph, content: nodes };
127127
};
128128

129129
if (content.length > 0) {
130-
content[0] = trimHardBreaks(content[0]);
130+
content[0] = trimHardBreaks(content[0], true, false);
131131
if (content.length > 1) {
132-
content[content.length - 1] = trimHardBreaks(content[content.length - 1]);
132+
content[content.length - 1] = trimHardBreaks(content[content.length - 1], false, true);
133133
}
134134
}
135135

web/pages/messages/[channelId].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const PrivateChat = (props: {
185185

186186
try {
187187
const content = cleanDoc(editor.getJSON())
188-
// console.log('submitting message', JSON.stringify(content))
188+
// console.log('submitting message\n', JSON.stringify(editor.getJSON()), JSON.stringify(content))
189189
if (editingMessage) {
190190
// console.log('editingMessage edit-message', editingMessage)
191191
setMessages((prevMessages) =>

0 commit comments

Comments
 (0)