diff --git a/autotests/chatkeyhelpertest.qml b/autotests/chatkeyhelpertest.qml index 76a8a48ce..67defdb00 100644 --- a/autotests/chatkeyhelpertest.qml +++ b/autotests/chatkeyhelpertest.qml @@ -31,12 +31,6 @@ TestCase { textItem: textItemHelper } - SignalSpy { - id: spyItem - target: textItemHelper - signalName: "textItemChanged" - } - SignalSpy { id: spyUp target: testHelper.keyHelper @@ -63,7 +57,6 @@ TestCase { function init(): void { textEdit.clear(); - spyItem.clear(); spyUp.clear(); spyDown.clear(); spyDelete.clear(); @@ -71,6 +64,11 @@ TestCase { textEdit.forceActiveFocus(); } + function cleanupTestCase(): void { + testHelper.textItem = null; + textItemHelper.textItem = null; + } + function test_upDown(): void { textEdit.insert(0, "line 1\nline 2\nline 3") textEdit.cursorPosition = 0; diff --git a/autotests/chatkeyhelpertesthelper.h b/autotests/chatkeyhelpertesthelper.h index 0322a2c7a..68d6259e1 100644 --- a/autotests/chatkeyhelpertesthelper.h +++ b/autotests/chatkeyhelpertesthelper.h @@ -30,14 +30,13 @@ public: ChatTextItemHelper *textItem() const { - return m_textItem; + return m_keyHelper->textItem; } void setTextItem(ChatTextItemHelper *textItem) { - if (textItem == m_textItem) { + if (textItem == m_keyHelper->textItem) { return; } - m_textItem = textItem; m_keyHelper->textItem = textItem; Q_EMIT textItemChanged(); } @@ -51,6 +50,5 @@ Q_SIGNALS: void textItemChanged(); private: - QPointer m_textItem; QPointer m_keyHelper; }; diff --git a/autotests/chattextitemhelpertest.qml b/autotests/chattextitemhelpertest.qml index 5265ee573..8ec9acfda 100644 --- a/autotests/chattextitemhelpertest.qml +++ b/autotests/chattextitemhelpertest.qml @@ -253,7 +253,6 @@ TestCase { compare(testHelper.checkFormatsAtCursor([]), true); testHelper.mergeFormatOnCursor(RichFormat.Strikethrough); compare(testHelper.checkFormatsAtCursor([RichFormat.Strikethrough]), true); - compare(testHelper.markdownText(), "***lots*** _of_ ~~text~~"); textEdit.clear(); textEdit.insert(0, "heading"); diff --git a/src/libneochat/chatkeyhelper.cpp b/src/libneochat/chatkeyhelper.cpp index 5bd5fbc03..8dce03b79 100644 --- a/src/libneochat/chatkeyhelper.cpp +++ b/src/libneochat/chatkeyhelper.cpp @@ -58,6 +58,10 @@ bool ChatKeyHelper::up(Qt::KeyboardModifiers modifiers) } if (modifiers.testFlag(Qt::ControlModifier)) { + const auto room = textItem->room(); + if (!room) { + return false; + } room->replyLastMessage(); return true; } diff --git a/src/libneochat/chatkeyhelper.h b/src/libneochat/chatkeyhelper.h index c1969e814..8a3e30a17 100644 --- a/src/libneochat/chatkeyhelper.h +++ b/src/libneochat/chatkeyhelper.h @@ -6,7 +6,6 @@ #include #include -class NeoChatRoom; class ChatTextItemHelper; /** @@ -26,13 +25,6 @@ class ChatKeyHelper : public QObject public: explicit ChatKeyHelper(QObject *parent = nullptr); - /** - * @brief The ChatTextItemHelper that ChatKeyHelper is handling key presses for. - * - * @sa ChatTextItemHelper - */ - QPointer room; - /** * @brief The ChatTextItemHelper that ChatKeyHelper is handling key presses for. * diff --git a/src/libneochat/chatmarkdownhelper.cpp b/src/libneochat/chatmarkdownhelper.cpp index d7fd1b2a6..ad32e21b2 100644 --- a/src/libneochat/chatmarkdownhelper.cpp +++ b/src/libneochat/chatmarkdownhelper.cpp @@ -23,18 +23,54 @@ const QList syntax = { MarkdownSyntax{.sequence = "*"_L1, .closable = true, .format = RichFormat::Italic}, MarkdownSyntax{.sequence = "**"_L1, .closable = true, .format = RichFormat::Bold}, MarkdownSyntax{.sequence = "# "_L1, .lineStart = true, .format = RichFormat::Heading1}, + MarkdownSyntax{.sequence = " # "_L1, .lineStart = true, .format = RichFormat::Heading1}, + MarkdownSyntax{.sequence = " # "_L1, .lineStart = true, .format = RichFormat::Heading1}, + MarkdownSyntax{.sequence = " # "_L1, .lineStart = true, .format = RichFormat::Heading1}, MarkdownSyntax{.sequence = "## "_L1, .lineStart = true, .format = RichFormat::Heading2}, + MarkdownSyntax{.sequence = " ## "_L1, .lineStart = true, .format = RichFormat::Heading2}, + MarkdownSyntax{.sequence = " ## "_L1, .lineStart = true, .format = RichFormat::Heading2}, + MarkdownSyntax{.sequence = " ## "_L1, .lineStart = true, .format = RichFormat::Heading2}, MarkdownSyntax{.sequence = "### "_L1, .lineStart = true, .format = RichFormat::Heading3}, + MarkdownSyntax{.sequence = " ### "_L1, .lineStart = true, .format = RichFormat::Heading3}, + MarkdownSyntax{.sequence = " ### "_L1, .lineStart = true, .format = RichFormat::Heading3}, + MarkdownSyntax{.sequence = " ### "_L1, .lineStart = true, .format = RichFormat::Heading3}, MarkdownSyntax{.sequence = "#### "_L1, .lineStart = true, .format = RichFormat::Heading4}, + MarkdownSyntax{.sequence = " #### "_L1, .lineStart = true, .format = RichFormat::Heading4}, + MarkdownSyntax{.sequence = " #### "_L1, .lineStart = true, .format = RichFormat::Heading4}, + MarkdownSyntax{.sequence = " #### "_L1, .lineStart = true, .format = RichFormat::Heading4}, MarkdownSyntax{.sequence = "##### "_L1, .lineStart = true, .format = RichFormat::Heading5}, + MarkdownSyntax{.sequence = " ##### "_L1, .lineStart = true, .format = RichFormat::Heading5}, + MarkdownSyntax{.sequence = " ##### "_L1, .lineStart = true, .format = RichFormat::Heading5}, + MarkdownSyntax{.sequence = " ##### "_L1, .lineStart = true, .format = RichFormat::Heading5}, MarkdownSyntax{.sequence = "###### "_L1, .lineStart = true, .format = RichFormat::Heading6}, - MarkdownSyntax{.sequence = "> "_L1, .lineStart = true, .format = RichFormat::Quote}, + MarkdownSyntax{.sequence = " ###### "_L1, .lineStart = true, .format = RichFormat::Heading6}, + MarkdownSyntax{.sequence = " ###### "_L1, .lineStart = true, .format = RichFormat::Heading6}, + MarkdownSyntax{.sequence = " ###### "_L1, .lineStart = true, .format = RichFormat::Heading6}, + MarkdownSyntax{.sequence = ">"_L1, .lineStart = true, .format = RichFormat::Quote}, + MarkdownSyntax{.sequence = " >"_L1, .lineStart = true, .format = RichFormat::Quote}, + MarkdownSyntax{.sequence = " >"_L1, .lineStart = true, .format = RichFormat::Quote}, + MarkdownSyntax{.sequence = " >"_L1, .lineStart = true, .format = RichFormat::Quote}, MarkdownSyntax{.sequence = "* "_L1, .lineStart = true, .format = RichFormat::UnorderedList}, + MarkdownSyntax{.sequence = " * "_L1, .lineStart = true, .format = RichFormat::UnorderedList}, + MarkdownSyntax{.sequence = " * "_L1, .lineStart = true, .format = RichFormat::UnorderedList}, + MarkdownSyntax{.sequence = " * "_L1, .lineStart = true, .format = RichFormat::UnorderedList}, MarkdownSyntax{.sequence = "- "_L1, .lineStart = true, .format = RichFormat::UnorderedList}, + MarkdownSyntax{.sequence = " - "_L1, .lineStart = true, .format = RichFormat::UnorderedList}, + MarkdownSyntax{.sequence = " - "_L1, .lineStart = true, .format = RichFormat::UnorderedList}, + MarkdownSyntax{.sequence = " - "_L1, .lineStart = true, .format = RichFormat::UnorderedList}, MarkdownSyntax{.sequence = "1. "_L1, .lineStart = true, .format = RichFormat::OrderedList}, + MarkdownSyntax{.sequence = " 1. "_L1, .lineStart = true, .format = RichFormat::OrderedList}, + MarkdownSyntax{.sequence = " 1. "_L1, .lineStart = true, .format = RichFormat::OrderedList}, + MarkdownSyntax{.sequence = " 1. "_L1, .lineStart = true, .format = RichFormat::OrderedList}, MarkdownSyntax{.sequence = "1) "_L1, .lineStart = true, .format = RichFormat::OrderedList}, + MarkdownSyntax{.sequence = " 1) "_L1, .lineStart = true, .format = RichFormat::OrderedList}, + MarkdownSyntax{.sequence = " 1) "_L1, .lineStart = true, .format = RichFormat::OrderedList}, + MarkdownSyntax{.sequence = " 1) "_L1, .lineStart = true, .format = RichFormat::OrderedList}, MarkdownSyntax{.sequence = "`"_L1, .closable = true, .format = RichFormat::InlineCode}, MarkdownSyntax{.sequence = "```"_L1, .lineStart = true, .format = RichFormat::Code}, + MarkdownSyntax{.sequence = " ```"_L1, .lineStart = true, .format = RichFormat::Code}, + MarkdownSyntax{.sequence = " ```"_L1, .lineStart = true, .format = RichFormat::Code}, + MarkdownSyntax{.sequence = " ```"_L1, .lineStart = true, .format = RichFormat::Code}, MarkdownSyntax{.sequence = "~~"_L1, .closable = true, .format = RichFormat::Strikethrough}, MarkdownSyntax{.sequence = "_"_L1, .closable = true, .format = RichFormat::Underline}, }; diff --git a/src/libneochat/chattextitemhelper.cpp b/src/libneochat/chattextitemhelper.cpp index 8665ee4c0..2cf0b0323 100644 --- a/src/libneochat/chattextitemhelper.cpp +++ b/src/libneochat/chattextitemhelper.cpp @@ -10,6 +10,7 @@ #include #include +#include #include "chatbarsyntaxhighlighter.h" #include "neochatroom.h" @@ -605,7 +606,7 @@ QString ChatTextItemHelper::markdownText() const if (!doc) { return {}; } - return trim(doc->toMarkdown()); + return trim(doc->toMarkdown(QTextDocument::MarkdownDialectGitHub)); } QString ChatTextItemHelper::plainText() const diff --git a/src/libneochat/enums/richformat.cpp b/src/libneochat/enums/richformat.cpp index a30b09a6b..bd712cdb5 100644 --- a/src/libneochat/enums/richformat.cpp +++ b/src/libneochat/enums/richformat.cpp @@ -3,6 +3,7 @@ #include "richformat.h" +#include #include #include #include @@ -195,19 +196,20 @@ QList RichFormat::formatsAtCursor(const QTextCursor &cursor) if (cursor.isNull()) { return formats; } - if (cursor.charFormat().fontWeight() == QFont::Bold) { + const auto format = cursor.charFormat(); + if (format.fontWeight() == QFont::Bold) { formats += Bold; } - if (cursor.charFormat().fontItalic()) { + if (format.fontItalic()) { formats += Italic; } - if (cursor.charFormat().fontUnderline()) { + if (format.fontUnderline()) { formats += Underline; } - if (cursor.charFormat().fontStrikeOut()) { + if (format.fontStrikeOut()) { formats += Strikethrough; } - if (cursor.charFormat().fontFixedPitch()) { + if (format.fontFixedPitch()) { formats += InlineCode; } if (cursor.blockFormat().headingLevel() > 0 && cursor.blockFormat().headingLevel() <= 6) { diff --git a/src/messagecontent/models/chatbarmessagecontentmodel.cpp b/src/messagecontent/models/chatbarmessagecontentmodel.cpp index 9fa009cec..db3f2df3a 100644 --- a/src/messagecontent/models/chatbarmessagecontentmodel.cpp +++ b/src/messagecontent/models/chatbarmessagecontentmodel.cpp @@ -45,7 +45,6 @@ ChatBarMessageContentModel::ChatBarMessageContentModel(QObject *parent) textItem->setRoom(m_room); } } - m_keyHelper->room = m_room; }); connect(this, &ChatBarMessageContentModel::typeChanged, this, [this](ChatBarType::Type oldType) { for (const auto &component : m_components) {