From 8d4ee724781c8d00be5cbfcce14028d222ef4f29 Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 3 Dec 2022 14:02:39 +0100 Subject: [PATCH] fix: Copy Shortcut Not Working In Reply Thread Popup (#4209) --- CHANGELOG.md | 1 + src/widgets/dialogs/ReplyThreadPopup.cpp | 3 ++- src/widgets/helper/ChannelView.cpp | 11 ++++++++++- src/widgets/helper/ChannelView.hpp | 8 ++++++++ src/widgets/splits/Split.cpp | 5 ----- src/widgets/splits/Split.hpp | 1 - src/widgets/splits/SplitInput.cpp | 12 +++++++----- src/widgets/splits/SplitInput.hpp | 4 +++- 8 files changed, 31 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4c1a97a4..cab0d0139 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Bugfix: Fixed CTRL + C not working in reply thread popups. (#4209) - Bugfix: Fixed message input showing as red after removing a message that was more than 500 characters. (#4204) - Bugfix: Fixed unnecessary saving of windows layout. (#4201) - Dev: Ignore `WM_SHOWWINDOW` hide events, causing fewer attempted rescales. (#4198) diff --git a/src/widgets/dialogs/ReplyThreadPopup.cpp b/src/widgets/dialogs/ReplyThreadPopup.cpp index 999ba994d..59fe4a5c5 100644 --- a/src/widgets/dialogs/ReplyThreadPopup.cpp +++ b/src/widgets/dialogs/ReplyThreadPopup.cpp @@ -81,7 +81,8 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, QWidget *parent, }); // Create SplitInput with inline replying disabled - this->ui_.replyInput = new SplitInput(this, this->split_, false); + this->ui_.replyInput = + new SplitInput(this, this->split_, this->ui_.threadView, false); this->bSignals_.emplace_back( getApp()->accounts->twitch.currentUserChanged.connect([this] { diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 81ba6d4a1..a7dddfac1 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -166,9 +166,13 @@ ChannelView::ChannelView(BaseWidget *parent, Split *split, Context context, this->updatePauses(); }); + // This shortcut is not used in splits, it's used in views that + // don't have a SplitInput like the SearchPopup or EmotePopup. + // See SplitInput::installKeyPressedEvent for the copy event + // from views with a SplitInput. auto shortcut = new QShortcut(QKeySequence::StandardKey::Copy, this); QObject::connect(shortcut, &QShortcut::activated, [this] { - crossPlatformCopy(this->getSelectedText()); + this->copySelectedText(); }); this->clickTimer_ = new QTimer(this); @@ -592,6 +596,11 @@ void ChannelView::clearSelection() queueLayout(); } +void ChannelView::copySelectedText() +{ + crossPlatformCopy(this->getSelectedText()); +} + void ChannelView::setEnableScrollingToBottom(bool value) { this->enableScrollingToBottom_ = value; diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 9fae53e4e..b41b1d2f7 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -77,9 +77,17 @@ public: void queueUpdate(); Scrollbar &getScrollBar(); + QString getSelectedText(); bool hasSelection(); void clearSelection(); + /** + * Copies the currently selected text to the users clipboard. + * + * @see ::getSelectedText() + */ + void copySelectedText(); + void setEnableScrollingToBottom(bool); bool getEnableScrollingToBottom() const; void setOverrideFlags(boost::optional value); diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index cf81012cb..4c218ac52 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -1121,11 +1121,6 @@ void Split::openSubPage() } } -void Split::copyToClipboard() -{ - crossPlatformCopy(this->view_->getSelectedText()); -} - void Split::startWatching() { #ifdef USEWEBENGINE diff --git a/src/widgets/splits/Split.hpp b/src/widgets/splits/Split.hpp index 9727400b3..9782f5269 100644 --- a/src/widgets/splits/Split.hpp +++ b/src/widgets/splits/Split.hpp @@ -168,7 +168,6 @@ public slots: void openBrowserPlayer(); void openInStreamlink(); void openWithCustomScheme(); - void copyToClipboard(); void startWatching(); void setFiltersDialog(); void showSearch(bool singleChannel); diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index f037520ca..9c5b5ee40 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -33,14 +33,16 @@ namespace chatterino { SplitInput::SplitInput(Split *_chatWidget, bool enableInlineReplying) - : SplitInput(_chatWidget, _chatWidget, enableInlineReplying) + : SplitInput(_chatWidget, _chatWidget, _chatWidget->view_, + enableInlineReplying) { } SplitInput::SplitInput(QWidget *parent, Split *_chatWidget, - bool enableInlineReplying) + ChannelView *_channelView, bool enableInlineReplying) : BaseWidget(parent) , split_(_chatWidget) + , channelView_(_channelView) , enableInlineReplying_(enableInlineReplying) { this->installEventFilter(this); @@ -562,7 +564,7 @@ void SplitInput::addShortcuts() if (copyFromSplit) { - this->split_->copyToClipboard(); + this->channelView_->copySelectedText(); } else { @@ -641,9 +643,9 @@ void SplitInput::installKeyPressedEvent() if ((event->key() == Qt::Key_C || event->key() == Qt::Key_Insert) && event->modifiers() == Qt::ControlModifier) { - if (this->split_->view_->hasSelection()) + if (this->channelView_->hasSelection()) { - this->split_->copyToClipboard(); + this->channelView_->copySelectedText(); event->accept(); } } diff --git a/src/widgets/splits/SplitInput.hpp b/src/widgets/splits/SplitInput.hpp index 18ae9cbe9..81a6b8afe 100644 --- a/src/widgets/splits/SplitInput.hpp +++ b/src/widgets/splits/SplitInput.hpp @@ -22,6 +22,7 @@ class InputCompletionPopup; class EffectLabel; class MessageThread; class ResizingTextEdit; +class ChannelView; // MessageOverflow is used for controlling how to guide the user into not // sending a message that will be discarded by Twitch @@ -42,7 +43,7 @@ class SplitInput : public BaseWidget public: SplitInput(Split *_chatWidget, bool enableInlineReplying = true); - SplitInput(QWidget *parent, Split *_chatWidget, + SplitInput(QWidget *parent, Split *_chatWidget, ChannelView *_channelView, bool enableInlineReplying = true); bool hasSelection() const; @@ -124,6 +125,7 @@ protected: bool shouldPreventInput(const QString &text) const; Split *const split_; + ChannelView *const channelView_; QObjectRef emotePopup_; QObjectRef inputCompletionPopup_;