[ChatView] Fix extra blank line at beginning (#6613)

This commit is contained in:
RickyRister 2026-02-21 06:36:35 -08:00 committed by GitHub
parent 189f3a7bbc
commit 5c3c3bfdba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -89,9 +89,9 @@ void ChatView::refreshBlockColors()
QTextBlockFormat fmt = block.blockFormat(); QTextBlockFormat fmt = block.blockFormat();
if (even) if (even)
fmt.setBackground(palette().window());
else
fmt.setBackground(palette().base()); fmt.setBackground(palette().base());
else
fmt.setBackground(palette().window());
fmt.setForeground(palette().text()); fmt.setForeground(palette().text());
@ -113,20 +113,28 @@ QTextCursor ChatView::prepareBlock(bool same)
{ {
lastSender.clear(); lastSender.clear();
QTextCursor cursor(document()); QTextDocument *doc = document();
QTextCursor cursor(doc);
cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::End);
if (same) { if (same) {
cursor.insertHtml("<br>"); cursor.insertHtml("<br>");
} else { } else {
QTextBlockFormat blockFormat; QTextBlockFormat blockFormat;
if ((evenNumber = !evenNumber)) if (evenNumber)
blockFormat.setBackground(palette().window());
else
blockFormat.setBackground(palette().base()); blockFormat.setBackground(palette().base());
else
blockFormat.setBackground(palette().window());
evenNumber = !evenNumber;
blockFormat.setForeground(palette().text()); blockFormat.setForeground(palette().text());
blockFormat.setBottomMargin(4); blockFormat.setBottomMargin(4);
cursor.insertBlock(blockFormat);
// Empty QTextDocuments still have 1 block. Just write to that block instead of inserting a new one
if (!doc->isEmpty()) {
cursor.insertBlock(blockFormat);
}
} }
return cursor; return cursor;