From 690bc0d385057d1bc7e2fb99b7a0021918769c9b Mon Sep 17 00:00:00 2001 From: James Graham Date: Sat, 7 Feb 2026 12:46:44 +0000 Subject: [PATCH] Revert to Paragraph format after a heading --- src/libneochat/chatkeyhelper.cpp | 8 +++++++- src/libneochat/enums/richformat.cpp | 6 +++++- src/libneochat/enums/richformat.h | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libneochat/chatkeyhelper.cpp b/src/libneochat/chatkeyhelper.cpp index c2f61dadf..5bd5fbc03 100644 --- a/src/libneochat/chatkeyhelper.cpp +++ b/src/libneochat/chatkeyhelper.cpp @@ -6,6 +6,7 @@ #include "chattextitemhelper.h" #include "clipboard.h" #include "neochatroom.h" +#include "richformat.h" ChatKeyHelper::ChatKeyHelper(QObject *parent) : QObject(parent) @@ -184,7 +185,12 @@ bool ChatKeyHelper::insertReturn(Qt::KeyboardModifiers modifiers) if (cursor.isNull()) { return false; } - cursor.insertBlock(); + + // If there was a heading we always want to revert to Paragraph format. + auto newBlockFormat = RichFormat::blockFormatForFormat(RichFormat::Paragraph); + auto newCharFormat = cursor.charFormat(); + newCharFormat.merge(RichFormat::charFormatForFormat(static_cast(cursor.blockFormat().headingLevel()), true)); + cursor.insertBlock(newBlockFormat, newCharFormat); return true; } diff --git a/src/libneochat/enums/richformat.cpp b/src/libneochat/enums/richformat.cpp index c24d034fa..f57ec1518 100644 --- a/src/libneochat/enums/richformat.cpp +++ b/src/libneochat/enums/richformat.cpp @@ -98,7 +98,11 @@ QTextCharFormat RichFormat::charFormatForFormat(Format format, bool invert, cons if (headingLevelForFormat(format) > 0) { // Apparently, 4 is maximum for FontSizeAdjustment; otherwise level=1 and // level=2 look the same - charFormat.setProperty(QTextFormat::FontSizeAdjustment, 5 - headingLevelForFormat(format)); + int fontSizeAdjustment = 0; + if (!invert) { + fontSizeAdjustment = 5 - headingLevelForFormat(format); + } + charFormat.setProperty(QTextFormat::FontSizeAdjustment, fontSizeAdjustment); } if (format == Paragraph) { charFormat.setFontWeight(QFont::Normal); diff --git a/src/libneochat/enums/richformat.h b/src/libneochat/enums/richformat.h index 894a51fdd..a13d621d8 100644 --- a/src/libneochat/enums/richformat.h +++ b/src/libneochat/enums/richformat.h @@ -39,8 +39,8 @@ public: Heading4 = 4, Heading5 = 5, Heading6 = 6, - Quote = 7, - Code = 8, + Quote, + Code, InlineCode, Bold, Italic,