From 2b8eefccca5bce535cd3f6b6415e1bf2d0fd48c7 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 8 Mar 2022 12:12:34 +0300 Subject: [PATCH] Returned Enter shortcut to confirm box. --- Telegram/SourceFiles/ui/boxes/confirm_box.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/ui/boxes/confirm_box.cpp b/Telegram/SourceFiles/ui/boxes/confirm_box.cpp index 92d3a05e2..cad5137eb 100644 --- a/Telegram/SourceFiles/ui/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/confirm_box.cpp @@ -42,13 +42,23 @@ void ConfirmBox(not_null box, ConfirmBoxArgs &&args) { const auto &defaultButtonStyle = box->getDelegate()->style().button; - box->addButton( + const auto confirmButton = box->addButton( v::text::take_plain(std::move(args.confirmText), tr::lng_box_ok()), [=, c = prepareCallback(args.confirmed)]() { lifetime->destroy(); c(); }, args.confirmStyle ? *args.confirmStyle : defaultButtonStyle); + box->events( + ) | rpl::start_with_next([=](not_null e) { + if ((e->type() != QEvent::KeyPress) || !confirmButton) { + return; + } + const auto k = static_cast(e.get()); + if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return) { + confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton); + } + }, box->lifetime()); if (!args.inform) { const auto cancelButton = box->addButton(