diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 3e84fba56..a48c34899 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -143,6 +143,8 @@ public: "/behaviour/autocompletion/prefixOnlyCompletion", true}; BoolSetting userCompletionOnlyWithAt = { "/behaviour/autocompletion/userCompletionOnlyWithAt", false}; + BoolSetting emoteCompletionWithColon = { + "/behaviour/autocompletion/emoteCompletionWithColon", true}; FloatSetting pauseOnHoverDuration = {"/behaviour/pauseOnHoverDuration", 0}; EnumSetting pauseChatModifier = { diff --git a/src/widgets/listview/GenericListView.cpp b/src/widgets/listview/GenericListView.cpp index 8eb4312d0..ca910387e 100644 --- a/src/widgets/listview/GenericListView.cpp +++ b/src/widgets/listview/GenericListView.cpp @@ -33,6 +33,11 @@ void GenericListView::setModel(GenericListModel *model) QListView::setModel(model); } +void GenericListView::setInvokeActionOnTab(bool value) +{ + this->invokeActionOnTab_ = value; +} + bool GenericListView::eventFilter(QObject * /*watched*/, QEvent *event) { if (!this->model_) @@ -47,30 +52,10 @@ bool GenericListView::eventFilter(QObject * /*watched*/, QEvent *event) const int curRow = curIdx.row(); const int count = this->model_->rowCount(curIdx); - if (key == Qt::Key_Down || key == Qt::Key_Tab) - { - if (count <= 0) - return true; - - const int newRow = (curRow + 1) % count; - - this->setCurrentIndex(curIdx.siblingAtRow(newRow)); - return true; - } - else if (key == Qt::Key_Up || key == Qt::Key_Backtab) - { - if (count <= 0) - return true; - - int newRow = curRow - 1; - if (newRow < 0) - newRow += count; - - this->setCurrentIndex(curIdx.siblingAtRow(newRow)); - return true; - } - else if (key == Qt::Key_Enter || key == Qt::Key_Return) + if (key == Qt::Key_Enter || key == Qt::Key_Return || + (key == Qt::Key_Tab && this->invokeActionOnTab_)) { + // keep this before the other tab handler if (count <= 0) return true; @@ -82,6 +67,29 @@ bool GenericListView::eventFilter(QObject * /*watched*/, QEvent *event) emit this->closeRequested(); return true; } + else if (key == Qt::Key_Down || key == Qt::Key_Tab) + { + if (count <= 0) + return true; + + const int newRow = (curRow + 1) % count; + + this->setCurrentIndex(curIdx.siblingAtRow(newRow)); + return true; + } + else if (key == Qt::Key_Up || + (!this->invokeActionOnTab_ && key == Qt::Key_Backtab)) + { + if (count <= 0) + return true; + + int newRow = curRow - 1; + if (newRow < 0) + newRow += count; + + this->setCurrentIndex(curIdx.siblingAtRow(newRow)); + return true; + } else if (key == Qt::Key_Escape) { emit this->closeRequested(); diff --git a/src/widgets/listview/GenericListView.hpp b/src/widgets/listview/GenericListView.hpp index 3baebf783..2faee1913 100644 --- a/src/widgets/listview/GenericListView.hpp +++ b/src/widgets/listview/GenericListView.hpp @@ -18,6 +18,7 @@ public: virtual void setModel(QAbstractItemModel *model) override; void setModel(GenericListModel *); + void setInvokeActionOnTab(bool); bool eventFilter(QObject *watched, QEvent *event) override; GenericListModel *model_{}; @@ -27,6 +28,9 @@ public: signals: void closeRequested(); + +private: + bool invokeActionOnTab_{}; }; } // namespace chatterino diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 9f9daf14e..9aa7d2025 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -474,6 +474,8 @@ void GeneralPage::initLayout(SettingsLayout &layout) layout.addCheckbox("Animate", s.animateEmotes); layout.addCheckbox("Animate only when Chatterino is focused", s.animationsWhenFocused); + layout.addCheckbox("Enable emote auto-completion by typing :", + s.emoteCompletionWithColon); layout.addDropdown( "Size", {"0.5x", "0.75x", "Default", "1.25x", "1.5x", "2x"}, s.emoteScale, diff --git a/src/widgets/splits/EmoteInputPopup.cpp b/src/widgets/splits/EmoteInputPopup.cpp index dd26d1f61..bd3d26ea1 100644 --- a/src/widgets/splits/EmoteInputPopup.cpp +++ b/src/widgets/splits/EmoteInputPopup.cpp @@ -62,6 +62,7 @@ void EmoteInputPopup::initLayout() auto listView = creator.emplace().assign(&this->ui_.listView); + listView->setInvokeActionOnTab(true); listView->setModel(&this->model_); QObject::connect(listView.getElement(), &GenericListView::closeRequested, diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index 4be21ef96..26ed484b7 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -459,9 +459,11 @@ void SplitInput::onCursorPositionChanged() void SplitInput::updateColonMenu() { - if (!dynamic_cast(this->split_->getChannel().get())) + if (!getSettings()->emoteCompletionWithColon || + !dynamic_cast(this->split_->getChannel().get())) { this->hideColonMenu(); + return; } // check if in :