From 3bf1756579d65c164c42f5382b7c5669f2772be8 Mon Sep 17 00:00:00 2001 From: kornes <28986062+kornes@users.noreply.github.com> Date: Mon, 16 May 2022 09:42:17 +0000 Subject: [PATCH] Fix: ignore whitespaces pasted in EmotePopup search (#3730) Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com> Co-authored-by: pajlada --- CHANGELOG.md | 2 +- chatterino.pro | 2 ++ src/CMakeLists.txt | 2 ++ src/widgets/dialogs/EmotePopup.cpp | 5 ++--- src/widgets/helper/RegExpItemDelegate.cpp | 5 +++-- src/widgets/helper/TrimRegExpValidator.cpp | 17 +++++++++++++++++ src/widgets/helper/TrimRegExpValidator.hpp | 19 +++++++++++++++++++ 7 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 src/widgets/helper/TrimRegExpValidator.cpp create mode 100644 src/widgets/helper/TrimRegExpValidator.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index cc4499ccb..9c83a6d12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - Minor: Sorted usernames in /vips message to be case-insensitive. (#3696) - Minor: Added option to open a user's chat in a new tab from the usercard profile picture context menu. (#3625) - Minor: Fixed tag parsing for consecutive escaped characters. (#3711) -- Minor: Prevent user from entering incorrect characters in Live Notifications channels list. (#3715) +- Minor: Prevent user from entering incorrect characters in Live Notifications channels list. (#3715, #3730) - Minor: Fixed automod caught message notice appearing twice for mods. (#3717) - Bugfix: Fixed live notifications for usernames containing uppercase characters. (#3646) - Bugfix: Fixed live notifications not getting updated for closed streams going offline. (#3678) diff --git a/chatterino.pro b/chatterino.pro index d0ee09f7e..8380ef9b5 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -306,6 +306,7 @@ SOURCES += \ src/widgets/helper/NotebookTab.cpp \ src/widgets/helper/QColorPicker.cpp \ src/widgets/helper/RegExpItemDelegate.cpp \ + src/widgets/helper/TrimRegExpValidator.cpp \ src/widgets/helper/ResizingTextEdit.cpp \ src/widgets/helper/ScrollbarHighlight.cpp \ src/widgets/helper/SearchPopup.cpp \ @@ -590,6 +591,7 @@ HEADERS += \ src/widgets/helper/NotebookTab.hpp \ src/widgets/helper/QColorPicker.hpp \ src/widgets/helper/RegExpItemDelegate.hpp \ + src/widgets/helper/TrimRegExpValidator.hpp \ src/widgets/helper/ResizingTextEdit.hpp \ src/widgets/helper/ScrollbarHighlight.hpp \ src/widgets/helper/SearchPopup.hpp \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1d419251b..a66f319a4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -422,6 +422,8 @@ set(SOURCE_FILES widgets/helper/QColorPicker.hpp widgets/helper/RegExpItemDelegate.cpp widgets/helper/RegExpItemDelegate.hpp + widgets/helper/TrimRegExpValidator.cpp + widgets/helper/TrimRegExpValidator.hpp widgets/helper/ResizingTextEdit.cpp widgets/helper/ResizingTextEdit.hpp widgets/helper/ScrollbarHighlight.cpp diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index fc43d2800..43de38b1a 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -15,11 +15,11 @@ #include "widgets/Notebook.hpp" #include "widgets/Scrollbar.hpp" #include "widgets/helper/ChannelView.hpp" +#include "widgets/helper/TrimRegExpValidator.hpp" #include #include #include -#include #include namespace chatterino { @@ -166,7 +166,6 @@ EmotePopup::EmotePopup(QWidget *parent) QRegularExpression searchRegex("\\S*"); searchRegex.setPatternOptions(QRegularExpression::CaseInsensitiveOption); - QValidator *searchValidator = new QRegularExpressionValidator(searchRegex); layout->setMargin(0); layout->setSpacing(0); @@ -177,7 +176,7 @@ EmotePopup::EmotePopup(QWidget *parent) this->search_ = new QLineEdit(); this->search_->setPlaceholderText("Search all emotes..."); - this->search_->setValidator(searchValidator); + this->search_->setValidator(new TrimRegExpValidator(searchRegex)); this->search_->setClearButtonEnabled(true); this->search_->findChild()->setIcon( QPixmap(":/buttons/clearSearch.png")); diff --git a/src/widgets/helper/RegExpItemDelegate.cpp b/src/widgets/helper/RegExpItemDelegate.cpp index d51eb52a2..d5f05e584 100644 --- a/src/widgets/helper/RegExpItemDelegate.cpp +++ b/src/widgets/helper/RegExpItemDelegate.cpp @@ -1,5 +1,7 @@ #include "widgets/helper/RegExpItemDelegate.hpp" +#include "widgets/helper/TrimRegExpValidator.hpp" + #include namespace chatterino { @@ -16,8 +18,7 @@ QWidget *RegExpItemDelegate::createEditor(QWidget *parent, const QModelIndex &index) const { auto *editor = new QLineEdit(parent); - editor->setValidator( - new QRegularExpressionValidator(this->regexp_, editor)); + editor->setValidator(new TrimRegExpValidator(this->regexp_, editor)); return editor; } diff --git a/src/widgets/helper/TrimRegExpValidator.cpp b/src/widgets/helper/TrimRegExpValidator.cpp new file mode 100644 index 000000000..4e0577f27 --- /dev/null +++ b/src/widgets/helper/TrimRegExpValidator.cpp @@ -0,0 +1,17 @@ +#include "widgets/helper/TrimRegExpValidator.hpp" + +namespace chatterino { + +TrimRegExpValidator::TrimRegExpValidator(const QRegularExpression &re, + QObject *parent) + : QRegularExpressionValidator(re, parent) +{ +} + +QValidator::State TrimRegExpValidator::validate(QString &input, int &pos) const +{ + input = input.trimmed(); + return QRegularExpressionValidator::validate(input, pos); +} + +} // namespace chatterino diff --git a/src/widgets/helper/TrimRegExpValidator.hpp b/src/widgets/helper/TrimRegExpValidator.hpp new file mode 100644 index 000000000..072232139 --- /dev/null +++ b/src/widgets/helper/TrimRegExpValidator.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +namespace chatterino { + +class TrimRegExpValidator : public QRegularExpressionValidator +{ + Q_OBJECT + +public: + TrimRegExpValidator(const QRegularExpression &re, + QObject *parent = nullptr); + + QValidator::State validate(QString &input, int &pos) const override; +}; + +} // namespace chatterino