From 4d12e86dbd54e3cf02a716a28ae1b41cd901d852 Mon Sep 17 00:00:00 2001 From: Ovidijus Parsiunas Date: Thu, 28 Nov 2024 22:58:11 +0900 Subject: [PATCH] ability to add a new text message when using the changeMessage method --- component/src/views/chat/messages/messageUtils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/component/src/views/chat/messages/messageUtils.ts b/component/src/views/chat/messages/messageUtils.ts index 796eafda6..f08cc6e4f 100644 --- a/component/src/views/chat/messages/messageUtils.ts +++ b/component/src/views/chat/messages/messageUtils.ts @@ -201,8 +201,10 @@ export class MessageUtils { msg.renderText(messageToEls[1].text.bubbleElement, newText); } else { const messageElements = msg.createElements(newText, messageToEls[0].role); - msg.elementRef.insertBefore(messageElements.outerContainer, msg.elementRef.firstChild); - // update messageElementRefs element reference + const nextElements = (messageToEls[1].html || messageToEls[1].files?.[0]) as MessageElements; + msg.elementRef.insertBefore(messageElements.outerContainer, nextElements.outerContainer); + const nextMsgElsIndex = msg.messageElementRefs.findIndex((messageElements) => messageElements === nextElements); + msg.messageElementRefs.splice(nextMsgElsIndex, 0, messageElements); messageToEls[1].text = messageElements; } messageToEls[0].text = newText;