From 7b8d86f45a2cfa57374579a3a3552268ec6edae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Fri, 9 Oct 2026 12:42:44 +0200 Subject: [PATCH] [UI] Keep focus in chat on Tab completion acceptance --- .../widgets/utility/line_edit_completer.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/interface/widgets/utility/line_edit_completer.cpp b/cockatrice/src/interface/widgets/utility/line_edit_completer.cpp index 7cb023848..95e335963 100644 --- a/cockatrice/src/interface/widgets/utility/line_edit_completer.cpp +++ b/cockatrice/src/interface/widgets/utility/line_edit_completer.cpp @@ -88,8 +88,7 @@ void LineEditCompleter::keyPressEvent(QKeyEvent *event) return; } - if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter || event->key() == Qt::Key_Space || - event->key() == Qt::Key_Tab) { + if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter || event->key() == Qt::Key_Space) { for (auto &info : completers) { if (info.completer->popup()->isVisible()) { event->ignore(); @@ -109,6 +108,27 @@ void LineEditCompleter::keyPressEvent(QKeyEvent *event) } } + if (event->key() == Qt::Key_Tab) { + for (auto &info : completers) { + if (info.completer->popup()->isVisible()) { + event->ignore(); + const QModelIndex currentIndex = info.completer->popup()->currentIndex(); + QString completionText; + if (currentIndex.isValid()) { + completionText = currentIndex.data().toString(); + } else { + completionText = info.completer->currentCompletion(); + } + if (!completionText.isEmpty()) { + insertCompletion(info.completer, completionText); + } + hideCompleterPopups(); + setFocus(); + return; + } + } + } + LineEditUnfocusable::keyPressEvent(event); QString textValue = text();