From 44bd3376cee24f4d4a689addeb94ba6f214dee86 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Fri, 26 Mar 2021 00:42:46 +0100 Subject: add /rainbow command --- src/timeline/InputBar.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 8a5e4346..2d76e7fb 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -255,7 +255,7 @@ InputBar::openFileSelection() } void -InputBar::message(QString msg, MarkdownOverride useMarkdown) +InputBar::message(QString msg, MarkdownOverride useMarkdown, bool rainbowify) { mtx::events::msg::Text text = {}; text.body = msg.trimmed().toStdString(); @@ -263,7 +263,7 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown) if ((ChatPage::instance()->userSettings()->markdown() && useMarkdown == MarkdownOverride::NOT_SPECIFIED) || useMarkdown == MarkdownOverride::ON) { - text.formatted_body = utils::markdownToHtml(msg).toStdString(); + text.formatted_body = utils::markdownToHtml(msg, rainbowify).toStdString(); // Remove markdown links by completer text.body = msg.trimmed().replace(conf::strings::matrixToMarkdownLink, "\\1").toStdString(); @@ -524,6 +524,8 @@ InputBar::command(QString command, QString args) message(args, MarkdownOverride::ON); } else if (command == "plain") { message(args, MarkdownOverride::OFF); + } else if (command == "rainbow") { + message(args, MarkdownOverride::NOT_SPECIFIED, true); } } -- cgit 1.5.1 From 4e6150f28e4b2fccc07e48b02ef957f4cee95297 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 28 Mar 2021 14:00:35 +0200 Subject: implement requested changes --- src/Utils.cpp | 17 +++++++---------- src/timeline/InputBar.cpp | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index 4be3c480..05e1a584 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -26,7 +26,6 @@ #include "Cache.h" #include "Config.h" #include "EventAccessors.h" -#include "Logging.h" #include "MatrixClient.h" #include "UserSettingsPage.h" @@ -509,24 +508,22 @@ utils::markdownToHtml(const QString &text, bool rainbowify) continue; // get text in current node - const char *tmp_buf = cmark_node_get_literal(cur); - std::string nodeText(tmp_buf); - auto qNodeText = QString::fromStdString(nodeText); + QString nodeText(cmark_node_get_literal(cur)); // create buffer to append rainbow text to std::string buf; int boundaryStart = 0; int boundaryEnd = 0; // use QTextBoundaryFinder to iterate ofer graphemes QTextBoundaryFinder tbf(QTextBoundaryFinder::BoundaryType::Grapheme, - qNodeText); + nodeText); while ((boundaryEnd = tbf.toNextBoundary()) != -1) { // Split text to get current char auto curChar = - qNodeText.mid(boundaryStart, boundaryEnd - boundaryStart); + nodeText.midRef(boundaryStart, boundaryEnd - boundaryStart); boundaryStart = boundaryEnd; - // Don't rainbowify spaces - if (curChar == " ") { - buf.push_back(' '); + // Don't rainbowify whitespaces + if (curChar.trimmed().isEmpty()) { + buf.append(curChar.toString().toStdString()); continue; } diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 2d76e7fb..69d129ce 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -525,7 +525,7 @@ InputBar::command(QString command, QString args) } else if (command == "plain") { message(args, MarkdownOverride::OFF); } else if (command == "rainbow") { - message(args, MarkdownOverride::NOT_SPECIFIED, true); + message(args, MarkdownOverride::ON, true); } } -- cgit 1.5.1 From ff2e7bb98934cc97047aad8e0fa28856a67df4eb Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 28 Mar 2021 14:49:34 +0200 Subject: commands now also work with newline after them --- src/timeline/InputBar.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 69d129ce..2e311169 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -204,6 +204,8 @@ InputBar::send() if (text().startsWith('/')) { int command_end = text().indexOf(' '); + if (command_end == -1) + command_end = text().indexOf('\n'); if (command_end == -1) command_end = text().size(); auto name = text().mid(1, command_end - 1); -- cgit 1.5.1 From 6c31bb6ddc88b5eccf2c24b47044da485231d002 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 28 Mar 2021 15:36:46 +0200 Subject: fix command parsing --- src/timeline/InputBar.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 2e311169..d7db50a9 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -15,6 +15,7 @@ #include #include +#include #include "Cache.h" #include "ChatPage.h" @@ -203,9 +204,7 @@ InputBar::send() auto wasEdit = !room->edit().isEmpty(); if (text().startsWith('/')) { - int command_end = text().indexOf(' '); - if (command_end == -1) - command_end = text().indexOf('\n'); + int command_end = text().indexOf(QRegExp("\\s+")); if (command_end == -1) command_end = text().size(); auto name = text().mid(1, command_end - 1); -- cgit 1.5.1 From 463dd206826d9fbe33b3ac10fadb438028a9eed9 Mon Sep 17 00:00:00 2001 From: "DeepBlueV7.X" Date: Sun, 28 Mar 2021 13:59:47 +0000 Subject: Use QRegularExpression --- src/timeline/InputBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index d7db50a9..0b498e82 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -204,7 +204,7 @@ InputBar::send() auto wasEdit = !room->edit().isEmpty(); if (text().startsWith('/')) { - int command_end = text().indexOf(QRegExp("\\s+")); + int command_end = text().indexOf(QRegularExpression("\\s")); if (command_end == -1) command_end = text().size(); auto name = text().mid(1, command_end - 1); -- cgit 1.5.1 From 3317d4582da791498e1fdd9a518052fbff243f92 Mon Sep 17 00:00:00 2001 From: "DeepBlueV7.X" Date: Sun, 28 Mar 2021 14:00:13 +0000 Subject: Update src/timeline/InputBar.cpp --- src/timeline/InputBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 0b498e82..a2c26b13 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include "Cache.h" #include "ChatPage.h" -- cgit 1.5.1 From 4b45c61024342834c4f91433ce7b17e73d60d33b Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 28 Mar 2021 17:37:36 +0200 Subject: run formatter --- src/Utils.cpp | 2 +- src/timeline/InputBar.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index 60b11e55..32d435f0 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -17,8 +17,8 @@ #include #include -#include #include +#include #include #include diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index a2c26b13..4a27b4bc 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -13,9 +13,9 @@ #include #include +#include #include #include -#include #include "Cache.h" #include "ChatPage.h" -- cgit 1.5.1