From 1ca5563fdb739e977ce9f592e3b1f2ae16d1f8a5 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Fri, 7 Aug 2026 10:11:14 +0200 Subject: [PATCH] gui: stream partial content to UI before newlines appendData() now emits dataChanged with partial line buffer content so the UI updates as tokens arrive, not just after complete lines. This fixes the laggy streaming where text would appear in chunks. --- gui/chatblockmodel.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gui/chatblockmodel.cpp b/gui/chatblockmodel.cpp index bac13f4..75da56a 100644 --- a/gui/chatblockmodel.cpp +++ b/gui/chatblockmodel.cpp @@ -172,6 +172,27 @@ void ChatBlockModel::appendData(const QString &text) m_lineBuffer = m_lineBuffer.mid(idx + 1); processLine(line); } + + // For streaming: update current block with partial line buffer content + // so the UI shows text as it arrives, not just after newlines. + if (!m_lineBuffer.isEmpty() && !m_blocks.isEmpty() && m_state == State::BlockEnd) { + ChatBlock &last = m_blocks.last(); + // Store the committed content length so we can update partial content + QString fullContent = last.content; + if (!fullContent.isEmpty() && !m_lineBuffer.isEmpty()) + fullContent += '\n'; + fullContent += m_lineBuffer; + + // Temporarily set content with partial line for rendering + QString savedContent = last.content; + last.content = fullContent; + rebuildBlockHtml(m_blocks.size() - 1); + last.content = savedContent; // Restore — partial line not committed yet + + // But emit with the rendered HTML that includes partial content + QModelIndex idx = index(m_blocks.size() - 1); + emit dataChanged(idx, idx, {RenderedHtmlRole}); + } } void ChatBlockModel::reset()