Skip to content

Commit

Permalink
fixing bugs with focusMode
Browse files Browse the repository at this point in the history
  • Loading branch information
OvidijusParsiunas committed Jan 8, 2025
1 parent 600cc59 commit 0c9eb5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion component/src/views/chat/messages/messagesBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class MessagesBase {
}

protected createAndAppendNewMessageElement(text: string, role: string) {
if (!this.focusMode) {
if (this.focusMode) {
return this.appendNewMessageElementFocusMode(text, role);
}
return this.createAndAppendNewMessageElementDefault(text, role);
Expand Down
7 changes: 4 additions & 3 deletions component/src/views/chat/messages/utils/updateMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class UpdateMessage {
const messageElements = HTMLMessages.create(msg, newHTML, messageToEls[0].role);
const previousElements = (messageToEls[1].files?.[messageToEls[1].files?.length - 1] ||
messageToEls[1].text) as MessageElements;
msg.elementRef.insertBefore(messageElements.outerContainer, previousElements.outerContainer.nextSibling);
const {nextSibling} = previousElements.outerContainer;
nextSibling?.parentElement?.insertBefore(messageElements.outerContainer, nextSibling);
msg.messageElementRefs.splice(msg.messageElementRefs.length - 1, 1); // removing as createMessageElements adds one
const prevMsgElsIndex = msg.messageElementRefs.findIndex((messageElements) => messageElements === previousElements);
msg.messageElementRefs.splice(prevMsgElsIndex + 1, 0, messageElements);
Expand All @@ -58,7 +59,7 @@ export class UpdateMessage {
const beforeElement = (nextElement?.outerContainer || prevElement?.outerContainer.nextSibling) as Node;
typeToElements.forEach(({type, elements}, index) => {
FileMessageUtils.setElementProps(msg, elements, type as keyof MessageStyles, role);
msg.elementRef.insertBefore(elements.outerContainer, beforeElement);
beforeElement.parentElement?.insertBefore(elements.outerContainer, beforeElement);
msg.messageElementRefs.splice(msg.messageElementRefs.length - 1, 1); // removing as createMessageElements adds one
msg.messageElementRefs.splice(siblingElementIndex + index, 0, elements);
});
Expand All @@ -73,7 +74,7 @@ export class UpdateMessage {
} else {
const messageElements = msg.createElements(newText, messageToEls[0].role);
const nextElements = (messageToEls[1].files?.[0] || messageToEls[1].html) as MessageElements;
msg.elementRef.insertBefore(messageElements.outerContainer, nextElements.outerContainer);
nextElements.outerContainer.parentElement?.insertBefore(messageElements.outerContainer, nextElements.outerContainer);
const nextMsgElsIndex = msg.messageElementRefs.findIndex((messageElements) => messageElements === nextElements);
msg.messageElementRefs.splice(nextMsgElsIndex, 0, messageElements);
messageToEls[1].text = messageElements;
Expand Down

0 comments on commit 0c9eb5e

Please sign in to comment.