Conditionally handle Tab in fields in custom way.

This commit is contained in:
John Preston
2026-02-09 14:02:36 +04:00
parent 998b3af598
commit 5c87c43007
8 changed files with 27 additions and 35 deletions
@@ -1571,16 +1571,15 @@ void EditNameBox::prepare() {
_last->submits(
) | rpl::on_next([=] { submit(); }, _last->lifetime());
_first->customTab(true);
_last->customTab(true);
_first->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
_last->setFocus();
*handled = true;
}, _first->lifetime());
_last->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
_first->setFocus();
*handled = true;
}, _last->lifetime());
}
@@ -246,7 +246,6 @@ Options::Option::Option(
InitField(outer, _field, session);
_field->setMaxLength(kOptionLimit + kErrorLimit);
_field->show();
_field->customTab(true);
_wrap->hide(anim::type::instant);
@@ -725,13 +724,14 @@ void Options::addEmptyOption() {
_scrollToWidget.fire_copy(field);
}, field->lifetime());
field->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
const auto index = findField(field);
if (index + 1 < _list.size()) {
_list[index + 1]->setFocus();
} else {
_tabbed.fire({});
}
*handled = true;
}, field->lifetime());
base::install_event_filter(field, [=](not_null<QEvent*> event) {
if (event->type() != QEvent::KeyPress
@@ -863,7 +863,6 @@ not_null<Ui::InputField*> CreatePollBox::setupQuestion(
InitField(getDelegate()->outerContainer(), question, session);
question->setMaxLength(kQuestionLimit + kErrorLimit);
question->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
question->customTab(true);
if (isPremium) {
using Selector = ChatHelpers::TabbedSelector;
@@ -968,7 +967,6 @@ not_null<Ui::InputField*> CreatePollBox::setupSolution(
));
solution->setEditLinkCallback(
DefaultEditLinkCallback(_controller->uiShow(), solution));
solution->customTab(true);
const auto warning = CreateWarningLabel(
inner,
@@ -1048,8 +1046,9 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
st::createPollLimitPadding));
question->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
options->focusFirst();
*handled = true;
}, question->lifetime());
Ui::AddSkip(container);
@@ -1097,8 +1096,9 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
}, question->lifetime());
solution->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
question->setFocus();
*handled = true;
}, solution->lifetime());
quiz->setDisabled(_disabled & PollData::Flag::Quiz);
@@ -303,8 +303,6 @@ Tasks::Task::Task(
_field->show();
if (locked) {
_field->setDisabled(true);
} else {
_field->customTab(true);
}
_wrap->hide(anim::type::instant);
@@ -766,13 +764,14 @@ void Tasks::initTaskField(not_null<Task*> task, TextWithEntities text) {
_scrollToWidget.fire_copy(field);
}, field->lifetime());
field->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
const auto index = findField(field);
if (index + 1 < _list.size()) {
_list[index + 1]->setFocus();
} else {
_tabbed.fire({});
}
*handled = true;
}, field->lifetime());
base::install_event_filter(field, [=](not_null<QEvent*> event) {
if (event->type() != QEvent::KeyPress
@@ -933,7 +932,6 @@ not_null<Ui::InputField*> EditTodoListBox::setupTitle(
InitField(getDelegate()->outerContainer(), title, session);
title->setMaxLength(_titleLimit + kErrorLimit);
title->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
title->customTab(true);
if (isPremium) {
_emojiPanel = MakeEmojiPanel(
@@ -1044,8 +1042,9 @@ object_ptr<Ui::RpWidget> EditTodoListBox::setupContent() {
st::createPollLimitPadding));
title->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
tasks->focusFirst();
*handled = true;
}, title->lifetime());
Ui::AddSkip(container);
@@ -1662,7 +1662,6 @@ void InitFieldAutocomplete(
const auto field = descriptor.field;
field->rawTextEdit()->installEventFilter(raw);
field->customTab(true);
raw->mentionChosen(
) | rpl::on_next([=](FieldAutocomplete::MentionChosen data) {
@@ -1727,9 +1726,10 @@ void InitFieldAutocomplete(
}
field->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
if (!raw->isHidden()) {
raw->chooseSelected(FieldAutocomplete::ChooseMethod::ByTab);
*handled = true;
}
}, raw->lifetime());
@@ -244,9 +244,6 @@ void EditLinkBox(
}
});
url->customTab(true);
text->customTab(true);
const auto clearFullSelection = [=](not_null<Ui::InputField*> input) {
if (input->empty()) {
return;
@@ -262,17 +259,20 @@ void EditLinkBox(
};
url->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
clearFullSelection(url);
text->setFocus();
*handled = true;
}, url->lifetime());
text->tabbed(
) | rpl::on_next([=] {
) | rpl::on_next([=](not_null<bool*> handled) {
if (!url->empty()) {
url->selectAll();
}
clearFullSelection(text);
url->setFocus();
*handled = true;
}, text->lifetime());
}
@@ -409,8 +409,11 @@ HistoryWidget::HistoryWidget(
escape();
}, _field->lifetime());
_field->tabbed(
) | rpl::on_next([=] {
fieldTabbed();
) | rpl::on_next([=](not_null<bool*> handled) {
if (_supportAutocomplete) {
_supportAutocomplete->activate(_field.data());
*handled = true;
}
}, _field->lifetime());
_field->heightChanges(
) | rpl::on_next([=] {
@@ -7881,14 +7884,6 @@ bool HistoryWidget::showSlowmodeError() {
return true;
}
void HistoryWidget::fieldTabbed() {
if (_supportAutocomplete) {
_supportAutocomplete->activate(_field.data());
}else{
focusNextPrevChild(true);
}
}
void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) {
if (!_peer || !_canSendMessages) {
return;
@@ -388,7 +388,6 @@ private:
void setTabbedPanel(std::unique_ptr<TabbedPanel> panel);
void updateField();
void fieldChanged();
void fieldTabbed();
void fieldFocused();
void fieldResized();