mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[UI] Refocus on Tab when completing
This commit is contained in:
parent
bc8289e48f
commit
c9ce34a00a
1 changed files with 25 additions and 20 deletions
|
|
@ -48,32 +48,37 @@ void LineEditCompleter::focusOutEvent(QFocusEvent *e)
|
|||
{
|
||||
LineEditUnfocusable::focusOutEvent(e);
|
||||
|
||||
// Only commit the highlighted completion when focus moves away via Tab.
|
||||
// Commit completion when focus moves away via Tab if popup is visible.
|
||||
// Other focus losses (e.g. the unfocus shortcut / Escape) must simply close
|
||||
// the popup without inserting anything.
|
||||
if (e->reason() != Qt::TabFocusReason) {
|
||||
hideCompleterPopups();
|
||||
bool popupWasVisible = false;
|
||||
for (auto &info : completers) {
|
||||
if (info.completer->popup()->isVisible()) {
|
||||
popupWasVisible = true;
|
||||
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();
|
||||
|
||||
if (popupWasVisible && e->reason() == Qt::TabFocusReason) {
|
||||
// Refocus the edit so Tab doesn't move focus away
|
||||
setFocus();
|
||||
e->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &info : completers) {
|
||||
if (!info.completer->popup()->isVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
if (popupWasVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
hideCompleterPopups();
|
||||
}
|
||||
|
||||
void LineEditCompleter::keyPressEvent(QKeyEvent *event)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue