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()