Skip to content

Commit

Permalink
Merge pull request #1042 from The-Commit-Company/1041-empty-paragraph…
Browse files Browse the repository at this point in the history
…s-at-the-end-of-the-message-should-be-removed

fix: remove trailing empty paragraphs when sending messages
  • Loading branch information
nikkothari22 authored Aug 31, 2024
2 parents d77e527 + e704b20 commit 5cc7e11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,32 @@ export const SendButton = ({ sendMessage, messageSending, setContent, ...props }
const onClick = () => {
if (editor) {


const hasContent = editor.getText().trim().length > 0

const hasInlineImage = editor.getHTML().includes('img')

let html = ''
let json = {}
let json: any = {}
if (hasContent || hasInlineImage) {
html = editor.getHTML()
json = editor.getJSON()

// remove empty paragraphs at the end of the content
const content = json.content

for (let i = content.length - 1; i >= 0; i--) {
if (content[i].type === 'paragraph' && (!content[i].content || content[i].content.length === 0)) {
content.pop()
} else {
break
}
}

json.content = content

// Get the HTMl content
editor.commands.setContent(json)

html = editor.getHTML()
}
editor.setEditable(false)
sendMessage(html, json)
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/feature/chat/ChatInput/Tiptap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ const Tiptap = ({ isEdit, slotBefore, fileProps, onMessageSend, replyMessage, cl
// followCursor: true,
offset: [90, 15],
inlinePositioning: true,
}}>
}}
editor={editor}>
<div className='bg-gray-1 dark:bg-gray-3 shadow-md p-2 rounded-md'>
<TextFormattingMenu />
</div>
Expand Down

0 comments on commit 5cc7e11

Please sign in to comment.