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);
|
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
|
// Other focus losses (e.g. the unfocus shortcut / Escape) must simply close
|
||||||
// the popup without inserting anything.
|
// the popup without inserting anything.
|
||||||
if (e->reason() != Qt::TabFocusReason) {
|
bool popupWasVisible = false;
|
||||||
hideCompleterPopups();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &info : completers) {
|
if (popupWasVisible) {
|
||||||
if (!info.completer->popup()->isVisible()) {
|
return;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hideCompleterPopups();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEditCompleter::keyPressEvent(QKeyEvent *event)
|
void LineEditCompleter::keyPressEvent(QKeyEvent *event)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue