diff --git a/Telegram/SourceFiles/ui/countryinput.cpp b/Telegram/SourceFiles/ui/countryinput.cpp index 3cb78ae180..49f5ebaff2 100644 --- a/Telegram/SourceFiles/ui/countryinput.cpp +++ b/Telegram/SourceFiles/ui/countryinput.cpp @@ -103,6 +103,42 @@ void CountryInput::mousePressEvent(QMouseEvent *e) { } } +void CountryInput::keyPressEvent(QKeyEvent* e) { + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) { + auto object = Box(); + const auto box = base::make_weak(object.data()); + _show->showBox(std::move(object), Ui::LayerOption::CloseOther); + box->entryChosen( + ) | rpl::start_with_next([=]( + const Ui::CountrySelectBox::Entry& entry) { + if (box) { + box->closeBox(); + } + + const auto& list = Countries::Instance().list(); + const auto infoIt = ranges::find( + list, + entry.iso2, + &Countries::Info::iso2); + if (infoIt == end(list)) { + return; + } + const auto info = *infoIt; + const auto it = ranges::find( + info.codes, + entry.code, + &Countries::CallingCodeInfo::callingCode); + if (it != end(info.codes)) { + chooseCountry( + &info, + std::distance(begin(info.codes), it)); + } + }, lifetime()); + } else { + RpWidget::keyPressEvent(e); + } +} + void CountryInput::enterEventHook(QEnterEvent *e) { setMouseTracking(true); } diff --git a/Telegram/SourceFiles/ui/countryinput.h b/Telegram/SourceFiles/ui/countryinput.h index 3ce0f04c6c..741bfdaeee 100644 --- a/Telegram/SourceFiles/ui/countryinput.h +++ b/Telegram/SourceFiles/ui/countryinput.h @@ -41,6 +41,7 @@ protected: void paintEvent(QPaintEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; void mousePressEvent(QMouseEvent *e) override; + void keyPressEvent(QKeyEvent* e) override; void enterEventHook(QEnterEvent *e) override; void leaveEventHook(QEvent *e) override;