Cleanup chatkeyhelp and tests
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<ChatTextItemHelper> m_textItem;
|
||||
QPointer<ChatKeyHelper> m_keyHelper;
|
||||
};
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
|
||||
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<NeoChatRoom> room;
|
||||
|
||||
/**
|
||||
* @brief The ChatTextItemHelper that ChatKeyHelper is handling key presses for.
|
||||
*
|
||||
|
||||
@@ -23,18 +23,54 @@ const QList<MarkdownSyntax> 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::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},
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <QTextDocumentFragment>
|
||||
|
||||
#include <Kirigami/Platform/PlatformTheme>
|
||||
#include <qtextdocument.h>
|
||||
|
||||
#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
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "richformat.h"
|
||||
|
||||
#include <QFontInfo>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextCursor>
|
||||
@@ -195,19 +196,20 @@ QList<RichFormat::Format> 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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user