Commit 300719d3 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Move focus to next (or previous) recipient field when removing one

If the recipient field to remove has focus, then we move the focus to
the next recipient field or, if the field to remove is the last one, to
the previous recipient field. Since there are at least two (empty) fields,
if we remove the field, we don't have to consider the case that there are
no remaining fields.

GnuPG-bug-id: 5535
parent b9a9ae10
......@@ -487,17 +487,20 @@ void SignEncryptWidget::recpRemovalRequested(CertificateLineEdit *w)
if (!w) {
return;
}
int emptyEdits = 0;
for (const CertificateLineEdit *edit : std::as_const(mRecpWidgets)) {
if (edit->isEmpty()) {
emptyEdits++;
}
if (emptyEdits > 1) {
mRecpLayout->removeWidget(w);
mRecpWidgets.removeAll(w);
w->deleteLater();
return;
const int emptyEdits =
std::count_if(std::cbegin(mRecpWidgets), std::cend(mRecpWidgets),
[](auto w) { return w->isEmpty(); });
if (emptyEdits > 1) {
if (w->hasFocus()) {
const int index = mRecpLayout->indexOf(w);
const auto focusWidget = (index < mRecpLayout->count() - 1) ?
mRecpLayout->itemAt(index + 1)->widget() :
mRecpLayout->itemAt(mRecpLayout->count() - 2)->widget();
focusWidget->setFocus();
}
mRecpLayout->removeWidget(w);
mRecpWidgets.removeAll(w);
w->deleteLater();
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment