From c5ad17261642af6a0454bf6bafde0d3931103018 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 23 Jul 2024 16:52:05 +0530 Subject: [PATCH] Keep loading animation at message end & reduce lists padding in Obsidian Previously loading animation would be at top of message. Moving it to bottom is more intuitve and easier to track. Remove white-space: pre from list elements. It was adding too much y axis padding to chat messages (and train of thought) --- src/interface/obsidian/src/chat_view.ts | 15 ++++++++++----- src/interface/obsidian/styles.css | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/interface/obsidian/src/chat_view.ts b/src/interface/obsidian/src/chat_view.ts index 121d0a87..efde958b 100644 --- a/src/interface/obsidian/src/chat_view.ts +++ b/src/interface/obsidian/src/chat_view.ts @@ -1299,13 +1299,18 @@ export class KhojChatView extends KhojPaneView { handleStreamResponse(newResponseElement: HTMLElement | null, rawResponse: string, loadingEllipsis: HTMLElement | null, replace = true) { if (!newResponseElement) return; - if (replace && newResponseElement.getElementsByClassName("lds-ellipsis").length > 0 && loadingEllipsis) { + // Remove loading ellipsis if it exists + if (newResponseElement.getElementsByClassName("lds-ellipsis").length > 0 && loadingEllipsis) newResponseElement.removeChild(loadingEllipsis); - } - if (replace) { - newResponseElement.innerHTML = ""; - } + // Clear the response element if replace is true + if (replace) newResponseElement.innerHTML = ""; + + // Append response to the response element newResponseElement.appendChild(this.formatHTMLMessage(rawResponse, false, replace)); + + // Append loading ellipsis if it exists + if (!replace && loadingEllipsis) newResponseElement.appendChild(loadingEllipsis); + // Scroll to bottom of chat view this.scrollChatToBottom(); } diff --git a/src/interface/obsidian/styles.css b/src/interface/obsidian/styles.css index afd8fd19..42c1b3ce 100644 --- a/src/interface/obsidian/styles.css +++ b/src/interface/obsidian/styles.css @@ -85,6 +85,12 @@ If your plugin does not need CSS, delete this file. margin-left: auto; white-space: pre-line; } +/* Override white-space for ul, ol, li under khoj-chat-message-text.khoj */ +.khoj-chat-message-text.khoj ul, +.khoj-chat-message-text.khoj ol, +.khoj-chat-message-text.khoj li { + white-space: normal; +} /* add left protrusion to khoj chat bubble */ .khoj-chat-message-text.khoj:after { content: '';