Engaged chat search on typing instead of focus in screen reader mode.

In screen reader mode, focusing the dialogs search field no longer opens
the suggestions panel or shows the cancel-search button. Search engages
only when the user types, stays engaged after clearing the query, and
disengages only on explicit Escape or the cancel-search button. Tab and
Backspace on an empty query no longer exit search in this mode.

Non-screen-reader behavior is unchanged.
This commit is contained in:
Reza Bakhshi Laktasaraei
2026-06-02 13:26:01 +03:30
committed by John Preston
parent 0152fa2aaa
commit b9aad5d250
2 changed files with 15 additions and 3 deletions
@@ -44,6 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/controls/swipe_handler.h"
#include "ui/painter.h"
#include "ui/rect.h"
#include "ui/screen_reader_mode.h"
#include "ui/ui_utility.h"
#include "lang/lang_keys.h"
#include "mainwindow.h"
@@ -1773,8 +1774,12 @@ void Widget::processSearchFocusChange() {
updateSuggestions(anim::type::normal);
}
bool Widget::searchActive() const {
return Ui::ScreenReaderModeActive() ? _searchEngaged : _searchHasFocus;
}
void Widget::updateSuggestions(anim::type animated) {
const auto suggest = (_searchHasFocus || _searchSuggestionsLocked)
const auto suggest = (searchActive() || _searchSuggestionsLocked)
&& !_searchState.inChat
&& (_inner->state() == WidgetState::Default);
if (anim::Disabled() || !session().data().chatsListLoaded()) {
@@ -3363,7 +3368,7 @@ void Widget::listScrollUpdated() {
void Widget::updateCancelSearch() {
const auto shown = !_searchState.query.isEmpty()
|| (!_searchState.inChat
&& (_searchHasFocus || _searchSuggestionsLocked));
&& (searchActive() || _searchSuggestionsLocked));
_cancelSearch->toggle(shown, anim::type::normal);
if (_searchState.inChat) {
_cancelSearch->setAccessibleName(shown
@@ -3400,6 +3405,9 @@ QString Widget::validateSearchQuery() {
void Widget::applySearchUpdate() {
auto copy = _searchState;
copy.query = validateSearchQuery();
if (Ui::ScreenReaderModeActive() && !copy.query.isEmpty()) {
_searchEngaged = true;
}
applySearchState(std::move(copy));
if (_chooseFromUser->toggled()
@@ -4173,7 +4181,8 @@ void Widget::keyPressEvent(QKeyEvent *e) {
//} else {
// e->ignore();
//}
} else if ((e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Tab)
} else if ((e->key() == Qt::Key_Backspace
|| (e->key() == Qt::Key_Tab && !Ui::ScreenReaderModeActive()))
&& _searchHasFocus
&& !_searchState.inChat
&& _searchState.query.isEmpty()) {
@@ -4404,6 +4413,7 @@ void Widget::setSearchQuery(const QString &query, int cursorPosition) {
}
bool Widget::cancelSearch(CancelSearchOptions options) {
_searchEngaged = false;
const auto clearingSuggestionsQuery = _suggestions
&& _suggestions->consumeSearchQuery(QString());
if (clearingSuggestionsQuery) {