diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 9575eb7b2..97d49a270 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -767,6 +767,10 @@ bool FieldAutocomplete::eventFilter(QObject *obj, QEvent *e) { ? _moderateKeyActivateCallback(key) : false; } + } else if (ev->modifiers() & Qt::ControlModifier) { + if (ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return) { + return _inner->chooseSelected(ChooseMethod::ByCtrlEnter); + } } } return QWidget::eventFilter(obj, e); @@ -1132,7 +1136,7 @@ void FieldAutocomplete::Inner::setRecentInlineBotsInRows(int32 bots) { void FieldAutocomplete::Inner::mousePressEvent(QMouseEvent *e) { selectByMouse(e->globalPos()); - if (e->button() == Qt::LeftButton) { + if (e->button() == Qt::LeftButton || e->button() == Qt::RightButton) { if (_overDelete && _sel >= 0 && _sel < (_mrows->empty() ? _hrows->size() : _recentInlineBotsInRows)) { bool removed = false; if (_mrows->empty()) { @@ -1162,7 +1166,15 @@ void FieldAutocomplete::Inner::mousePressEvent(QMouseEvent *e) { selectByMouse(e->globalPos()); } else if (_srows->empty()) { - chooseSelected(FieldAutocomplete::ChooseMethod::ByClick); + if (e->button() == Qt::LeftButton) { + if (e->modifiers() & Qt::ControlModifier) { + chooseSelected(FieldAutocomplete::ChooseMethod::ByCtrlClick); + } else { + chooseSelected(FieldAutocomplete::ChooseMethod::ByClick); + } + } else if (e->button() == Qt::RightButton) { + chooseSelected(FieldAutocomplete::ChooseMethod::ByRightClick); + } } else { _down = _sel; _previewTimer.callOnce(QApplication::startDragTime()); @@ -1185,7 +1197,15 @@ void FieldAutocomplete::Inner::mouseReleaseEvent(QMouseEvent *e) { if (_sel < 0 || _sel != pressed || _srows->empty()) return; - chooseSelected(FieldAutocomplete::ChooseMethod::ByClick); + if (e->button() == Qt::LeftButton) { + if (e->modifiers() & Qt::ControlModifier) { + chooseSelected(FieldAutocomplete::ChooseMethod::ByCtrlClick); + } else { + chooseSelected(FieldAutocomplete::ChooseMethod::ByClick); + } + } else if (e->button() == Qt::RightButton) { + chooseSelected(FieldAutocomplete::ChooseMethod::ByRightClick); + } } void FieldAutocomplete::Inner::contextMenuEvent(QContextMenuEvent *e) { diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index b6a3e0e08..1ae344405 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -69,6 +69,9 @@ public: ByEnter, ByTab, ByClick, + ByRightClick, + ByCtrlEnter, + ByCtrlClick, }; struct MentionChosen { not_null user; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index cc9151321..814e71be9 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -389,7 +389,7 @@ HistoryWidget::HistoryWidget( _fieldAutocomplete->mentionChosen( ) | rpl::start_with_next([=](FieldAutocomplete::MentionChosen data) { - insertMention(data.user); + insertMention(data.user, data.method); }, lifetime()); _fieldAutocomplete->hashtagChosen( @@ -1420,9 +1420,12 @@ void HistoryWidget::start() { session().data().stickers().notifySavedGifsUpdated(); } -void HistoryWidget::insertMention(UserData *user) { +void HistoryWidget::insertMention(UserData *user, FieldAutocomplete::ChooseMethod method) { QString replacement, entityTag; - if (user->username.isEmpty()) { + if (user->username.isEmpty() + || method == FieldAutocomplete::ChooseMethod::ByRightClick + || method == FieldAutocomplete::ChooseMethod::ByCtrlEnter + || method == FieldAutocomplete::ChooseMethod::ByCtrlClick) { replacement = user->firstName; if (replacement.isEmpty()) { replacement = user->name; diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 5ca47f537..6fd95a6b0 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -357,7 +357,7 @@ private: void insertHashtagOrBotCommand( QString str, FieldAutocomplete::ChooseMethod method); - void insertMention(UserData *user); + void insertMention(UserData *user, FieldAutocomplete::ChooseMethod method); void cancelInlineBot(); void saveDraft(bool delayed = false); void saveCloudDraft(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index a16085f87..3a70fed73 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1220,8 +1220,11 @@ void ComposeControls::initAutocomplete() { _field->insertTag(string); } }; - const auto insertMention = [=](not_null user) { - if (user->username.isEmpty()) { + const auto insertMention = [=](not_null user, FieldAutocomplete::ChooseMethod method) { + if (user->username.isEmpty() + || method == FieldAutocomplete::ChooseMethod::ByRightClick + || method == FieldAutocomplete::ChooseMethod::ByCtrlEnter + || method == FieldAutocomplete::ChooseMethod::ByCtrlClick) { _field->insertTag( user->firstName.isEmpty() ? user->name : user->firstName, PrepareMentionTag(user)); @@ -1232,7 +1235,7 @@ void ComposeControls::initAutocomplete() { _autocomplete->mentionChosen( ) | rpl::start_with_next([=](FieldAutocomplete::MentionChosen data) { - insertMention(data.user); + insertMention(data.user, data.method); }, _autocomplete->lifetime()); _autocomplete->hashtagChosen(