From 1af985fde9a5722d41f58e7a6fcc51fa4f72107b Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Tue, 18 Oct 2022 18:24:35 -0400 Subject: [PATCH] Allow picking tags from completion menu with keyboard * Also fixes the hiding and display of the completion menu to be more natural and less annoying. * Fixes #7939 --- src/gui/tag/TagsEdit.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gui/tag/TagsEdit.cpp b/src/gui/tag/TagsEdit.cpp index 52fc4853e..7d5b657ce 100644 --- a/src/gui/tag/TagsEdit.cpp +++ b/src/gui/tag/TagsEdit.cpp @@ -413,9 +413,9 @@ struct TagsEdit::Impl void setupCompleter() { completer->setWidget(ifce); - connect(completer.get(), static_cast(&QCompleter::activated), [this](QString const& text) { - currentText(text); - }); + connect(completer.get(), + static_cast(&QCompleter::activated), + [this](QString const& text) { currentText(text); }); } QVector formatting() const @@ -861,10 +861,16 @@ void TagsEdit::keyPressEvent(QKeyEvent* event) case Qt::Key_Enter: case Qt::Key_Comma: case Qt::Key_Semicolon: + // If completer is visible, accept the selection or hide if no selection + if (impl->completer->popup()->isVisible() && impl->completer->popup()->selectionModel()->hasSelection()) { + break; + } + + // Make existing text into a tag if (!impl->currentText().isEmpty()) { impl->editNewTag(impl->editing_index + 1); + event->accept(); } - event->accept(); break; default: unknown = true;