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.
This commit is contained in:
Levi Neely 2026-08-07 10:11:14 +02:00
parent bb1454f85a
commit 1ca5563fdb
1 changed files with 21 additions and 0 deletions

View File

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