Fix focus search on topic open.

This commit is contained in:
John Preston 2024-08-15 09:48:59 +02:00
parent 520de600a0
commit 7d52c13625

View file

@ -1185,23 +1185,32 @@ Image *MainWidget::newBackgroundThumb() {
}
void MainWidget::setInnerFocus() {
const auto setTo = [&](auto &&widget) {
if (widget->isHidden()) {
// If we try setting focus inside a hidden widget, we may
// end up focusing search field in dialogs on window activation.
setFocus();
} else {
widget->setInnerFocus();
}
};
if (_dialogs && _dialogs->searchHasFocus()) {
_dialogs->setInnerFocus();
setTo(_dialogs);
} else if (_hider || !_history->peer()) {
if (!_hider && _mainSection) {
_mainSection->setInnerFocus();
setTo(_mainSection);
} else if (!_hider && _thirdSection) {
_thirdSection->setInnerFocus();
setTo(_thirdSection);
} else if (_dialogs) {
_dialogs->setInnerFocus();
setTo(_dialogs);
} else {
// Maybe we're just closing a child window, content is destroyed.
_history->setFocus();
}
} else if (_mainSection) {
_mainSection->setInnerFocus();
setTo(_mainSection);
} else {
_history->setInnerFocus();
setTo(_history);
}
}