[Improvement] Allow to mention by name from autocomplete

This commit is contained in:
Eric Kotato 2022-09-11 05:46:53 +03:00
parent 0a4eebfa98
commit 6fb484d618
5 changed files with 39 additions and 10 deletions

View file

@ -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()) {
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;
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) {

View file

@ -69,6 +69,9 @@ public:
ByEnter,
ByTab,
ByClick,
ByRightClick,
ByCtrlEnter,
ByCtrlClick,
};
struct MentionChosen {
not_null<UserData*> user;

View file

@ -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;

View file

@ -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();

View file

@ -1220,8 +1220,11 @@ void ComposeControls::initAutocomplete() {
_field->insertTag(string);
}
};
const auto insertMention = [=](not_null<UserData*> user) {
if (user->username.isEmpty()) {
const auto insertMention = [=](not_null<UserData*> 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(