Revert to Paragraph format after a heading

This commit is contained in:
James Graham
2026-02-07 12:46:44 +00:00
parent c32235ffe3
commit 690bc0d385
3 changed files with 14 additions and 4 deletions

View File

@@ -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<RichFormat::Format>(cursor.blockFormat().headingLevel()), true));
cursor.insertBlock(newBlockFormat, newCharFormat);
return true;
}

View File

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

View File

@@ -39,8 +39,8 @@ public:
Heading4 = 4,
Heading5 = 5,
Heading6 = 6,
Quote = 7,
Code = 8,
Quote,
Code,
InlineCode,
Bold,
Italic,