mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-02-07 12:31:01 -05:00
Fix: trim hardbreak only at start and end
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user