diff options
author | Dexter Gaon-Shatford <dexter@gaonshatford.ca> | 2022-04-08 21:08:15 +0300 |
---|---|---|
committer | Dexter Gaon-Shatford <dexter@gaonshatford.ca> | 2022-04-08 22:31:42 +0300 |
commit | ae097d6354d99325093dd5a12cb8632e2ba20edf (patch) | |
tree | 90eddae1099ceedb8cdf96963342888a0c1ddbbc /src | |
parent | aa62d87feab6cb849d0ead9945964c220d31eb88 (diff) |
FIX(client): resolve list tags, etc. polluting log
As reported in #4491, #4986 and #5430, since the changes to the chat in
the 1.4.x release, some tags would "pollute" the rest of the log, i.e.
cause future log entries to be contained within them.
The source of the issue seems to be that the `insertBlock` method of
`QTextCursor` appears to correspond to the `<p>` HTML tag. The `<p>` tag
may only contain inline elements, but `QTextEdit` will not fail outright
when inserting block-level elements and will instead attempt to correct
the invalid input which results in the behaviour reported in the above
issues (as far as I can tell).
My proposed solution is to use the `insertFrame` method for all
messages.
Fixes #4491
Diffstat (limited to 'src')
-rw-r--r-- | src/mumble/Log.cpp | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/mumble/Log.cpp b/src/mumble/Log.cpp index 54d7efc13..f77cba970 100644 --- a/src/mumble/Log.cpp +++ b/src/mumble/Log.cpp @@ -642,9 +642,7 @@ QString Log::validHtml(const QString &html, QTextCursor *tc) { } if (tc) { - QTextCursor tcNew(&qtd); - tcNew.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); - tc->insertFragment(tcNew.selection()); + tc->insertHtml(qtd.toHtml()); return QString(); } else { return qtd.toHtml(); @@ -675,11 +673,6 @@ void Log::log(MsgType mt, const QString &console, const QString &terse, bool own // the setting might change in that time). const int msgMargin = Global::get().s.iChatMessageMargins; - QTextBlockFormat format = tc.blockFormat(); - format.setTopMargin(msgMargin); - format.setBottomMargin(msgMargin); - tc.setBlockFormat(format); - LogTextBrowser *tlog = Global::get().mw->qteLog; const int oldscrollvalue = tlog->getLogScroll(); const bool scroll = (oldscrollvalue == tlog->getLogScrollMaximum()); @@ -698,24 +691,25 @@ void Log::log(MsgType mt, const QString &console, const QString &terse, bool own QString fixedNLPlain = plain.replace(QLatin1String("\r\n"), QLatin1String("\n")).replace(QLatin1String("\r"), QLatin1String("\n")); + QTextFrameFormat qttf; + // `insertFrame` causes a blank line to precede the inserted frame. + // This is remedied by setting a negative top margin of equal height. + static int lineSpacing = QFontMetrics(tc.currentFrame()->format().toCharFormat().font()).lineSpacing(); + qttf.setTopMargin(-lineSpacing); + qttf.setBottomMargin(msgMargin); + if (fixedNLPlain.contains(QRegExp(QLatin1String("\\n[ \\t]*$")))) { // If the message ends with one or more blank lines (or lines only containing whitespace) // paint a border around the message to make clear that it contains invisible parts. // The beginning of the message is clear anyway (the date and potentially the "To XY" part) // so we don't have to care about that. - QTextFrameFormat qttf; qttf.setBorder(1); qttf.setPadding(2); - qttf.setMargin(msgMargin); qttf.setBorderStyle(QTextFrameFormat::BorderStyle_Dashed); - tc.insertFrame(qttf); - } else if (!tc.block().text().isEmpty()) { - // Only insert a block if the current block is not empty. It may be empty because - // it is the default block of an empty document. Another cause might be that apparently - // a new empty block is automatically inserted after a frame. - tc.insertBlock(); } + tc.insertFrame(qttf); + const QString timeString = dt.time().toString(QLatin1String(Global::get().s.bLog24HourClock ? "HH:mm:ss" : "hh:mm:ss AP")); tc.insertHtml(Log::msgColor(QString::fromLatin1("[%1] ").arg(timeString.toHtmlEscaped()), Log::Time)); |