From 1836160538443e2a7c9eea540154a65a7f83ef18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Fri, 9 Oct 2026 12:12:49 +0200 Subject: [PATCH] [UI] Fix auto-completion acceptance on Space/Tab/Enter --- .../widgets/utility/line_edit_completer.cpp | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/interface/widgets/utility/line_edit_completer.cpp b/cockatrice/src/interface/widgets/utility/line_edit_completer.cpp index 38e3e4350..d1aff51bf 100644 --- a/cockatrice/src/interface/widgets/utility/line_edit_completer.cpp +++ b/cockatrice/src/interface/widgets/utility/line_edit_completer.cpp @@ -72,13 +72,33 @@ void LineEditCompleter::focusOutEvent(QFocusEvent *e) void LineEditCompleter::keyPressEvent(QKeyEvent *event) { - LineEditUnfocusable::keyPressEvent(event); - if (event->key() == Qt::Key_Escape) { - hideCompleterPopups(); + if (hasVisibleCompleterPopup()) { + event->ignore(); + hideCompleterPopups(); + return; + } + LineEditUnfocusable::keyPressEvent(event); return; } + if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter || event->key() == Qt::Key_Space || + event->key() == Qt::Key_Tab) { + for (auto &info : completers) { + if (info.completer->popup()->isVisible()) { + event->ignore(); + const QModelIndex currentIndex = info.completer->popup()->currentIndex(); + if (currentIndex.isValid()) { + insertCompletion(info.completer, currentIndex.data().toString()); + } + hideCompleterPopups(); + return; + } + } + } + + LineEditUnfocusable::keyPressEvent(event); + QString textValue = text(); int cursorPos = cursorPosition();