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() { 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()) { if (_dialogs && _dialogs->searchHasFocus()) {
_dialogs->setInnerFocus(); setTo(_dialogs);
} else if (_hider || !_history->peer()) { } else if (_hider || !_history->peer()) {
if (!_hider && _mainSection) { if (!_hider && _mainSection) {
_mainSection->setInnerFocus(); setTo(_mainSection);
} else if (!_hider && _thirdSection) { } else if (!_hider && _thirdSection) {
_thirdSection->setInnerFocus(); setTo(_thirdSection);
} else if (_dialogs) { } else if (_dialogs) {
_dialogs->setInnerFocus(); setTo(_dialogs);
} else { } else {
// Maybe we're just closing a child window, content is destroyed. // Maybe we're just closing a child window, content is destroyed.
_history->setFocus(); _history->setFocus();
} }
} else if (_mainSection) { } else if (_mainSection) {
_mainSection->setInnerFocus(); setTo(_mainSection);
} else { } else {
_history->setInnerFocus(); setTo(_history);
} }
} }