From b2446c83d2a915ed909799ff50f11e79be7eb723 Mon Sep 17 00:00:00 2001 From: tarai-dl Date: Fri, 17 Apr 2026 08:42:39 +0000 Subject: [PATCH] Fix autocomplete stealing keyboard focus on Windows The autocomplete popup calls listWidgetRef_->setFocus() when shown, which steals keyboard focus from the editor. When the popup closes (Enter, Tab, Escape, or other keys), focus was never restored to the editor component, preventing further typing. Fix by restoring focus to editorComponentRef_ in three places: 1. hideEvent() - catch-all when popup is hidden for any reason 2. Escape key handler - immediate restoration on cancel 3. Enter/Tab full word match and default key handlers Fixes Mudlet/Mudlet#5310 --- .../views/components/texteditorautocompletecomponent.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp b/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp index 3c23332..7b9d63e 100644 --- a/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp +++ b/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp @@ -323,6 +323,10 @@ void TextEditorAutoCompleteComponent::positionWidgetForCaretOffset(size_t offset void TextEditorAutoCompleteComponent::hideEvent(QHideEvent* event) { infoTipRef_->hide(); + // Restore focus to the editor when autocomplete is hidden + if (editorComponentRef_) { + editorComponentRef_->setFocus(); + } event->isAccepted(); } @@ -353,6 +357,7 @@ bool TextEditorAutoCompleteComponent::eventFilter(QObject *obj, QEvent *event) case Qt::Key_Escape: menuRef_->close(); canceled_ = true; + editorComponentRef_->setFocus(); return true; // stop event case Qt::Key_Enter: @@ -360,6 +365,7 @@ bool TextEditorAutoCompleteComponent::eventFilter(QObject *obj, QEvent *event) case Qt::Key_Tab: if (listWidgetRef_->currentItem() && currentWord_ == listWidgetRef_->currentItem()->text()) { // sends normal enter/return/tab if you've typed a full word menuRef_->close(); + editorComponentRef_->setFocus(); QApplication::sendEvent(editorComponentRef_, event); return true; } else if (listWidgetRef_->currentItem()) { @@ -388,6 +394,7 @@ bool TextEditorAutoCompleteComponent::eventFilter(QObject *obj, QEvent *event) // default operation is to hide and continue the event menuRef_->close(); + editorComponentRef_->setFocus(); QApplication::sendEvent(editorComponentRef_, event); return true;