[UI] Fix auto-completion acceptance on Space/Tab/Enter

This commit is contained in:
Lukas Brübach 2026-10-09 12:12:49 +02:00
parent bb61617d42
commit 1836160538

View file

@ -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();