Merge pull request #21633 from hrydgard/searchfixes

Some search fixes (fixes type-to-search on Mac, fix cheat search function on iOS)
This commit is contained in:
Henrik Rydgård
2026-05-04 15:21:11 +02:00
committed by GitHub
9 changed files with 39 additions and 7 deletions
+12 -1
View File
@@ -800,7 +800,7 @@ void AskForInput(ScreenManager *screenManager, RequesterToken token, UI::View *s
popupScreen->SetAlignTop(true);
}
popupScreen->OnChange.Add([callback, sourceView](EventParams &e) {
callback(SanitizeString(StripSpaces(*(std::string *)e.v), StringRestriction::None, 0, 0), true);
callback(SanitizeString(StripSpaces(e.s), StringRestriction::None, 0, 0), true);
if (sourceView) {
SetFocusedView(sourceView);
}
@@ -838,6 +838,7 @@ void PopupTextInputChoice::HandleClick(EventParams &e) {
*value_ = StripSpaces(SanitizeString(*value_, restriction_, minLen_, maxLen_));
EventParams params{};
params.v = this;
params.s = *value_;
OnChange.Trigger(params);
if (restoreFocus_) {
SetFocusedView(this);
@@ -949,6 +950,15 @@ ViewGroup *CreateSoftKeyboard(TextEdit *edit, SoftKeyboardState *state) {
return scrollView;
}
TextEditPopupScreen::TextEditPopupScreen(std::string *value, std::string_view placeholder, std::string_view title, int maxLen)
: PopupScreen(title, T(I18NCat::DIALOG, "OK"), T(I18NCat::DIALOG, "Cancel")), value_(value), placeholder_(placeholder), maxLen_(maxLen) {
if (!value_) {
// Point it to our temporary.
value_ = &textEditValue_;
}
}
void TextEditPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
using namespace UI;
UIContext &dc = *screenManager()->getUIContext();
@@ -982,6 +992,7 @@ void TextEditPopupScreen::OnCompleted(DialogResult result) {
*value_ = StripSpaces(edit_->GetText());
EventParams e{};
e.v = edit_;
e.s = *value_;
OnChange.Trigger(e);
}
}
+1 -2
View File
@@ -233,8 +233,7 @@ ViewGroup *CreateSoftKeyboard(TextEdit *edit, SoftKeyboardState *state);
class TextEditPopupScreen : public PopupScreen {
public:
TextEditPopupScreen(std::string *value, std::string_view placeholder, std::string_view title, int maxLen)
: PopupScreen(title, T(I18NCat::DIALOG, "OK"), T(I18NCat::DIALOG, "Cancel")), value_(value), placeholder_(placeholder), maxLen_(maxLen) {}
TextEditPopupScreen(std::string *value, std::string_view placeholder, std::string_view title, int maxLen);
void CreatePopupContents(ViewGroup *parent) override;
const char *tag() const override { return "TextEditPopup"; }
+16 -2
View File
@@ -15,8 +15,22 @@
void Screen::focusChanged(ScreenFocusChange focusChange) {
const char *eventName = "";
switch (focusChange) {
case ScreenFocusChange::FOCUS_LOST_TOP: eventName = "FOCUS_LOST_TOP"; break;
case ScreenFocusChange::FOCUS_BECAME_TOP: eventName = "FOCUS_BECAME_TOP"; break;
case ScreenFocusChange::FOCUS_LOST_TOP:
#if !defined(MOBILE_DEVICE)
if (WantsTextInput()) {
System_NotifyUIEvent(UIEventNotification::TEXT_LOSTFOCUS);
}
#endif
eventName = "FOCUS_LOST_TOP";
break;
case ScreenFocusChange::FOCUS_BECAME_TOP:
#if !defined(MOBILE_DEVICE)
if (WantsTextInput()) {
System_NotifyUIEvent(UIEventNotification::TEXT_GOTFOCUS);
}
#endif
eventName = "FOCUS_BECAME_TOP";
break;
}
DEBUG_LOG(Log::UI, "Screen %s got %s", this->tag(), eventName);
}
+1
View File
@@ -113,6 +113,7 @@ public:
virtual bool isTopLevel() const { return false; }
virtual TouchInput transformTouch(const TouchInput &touch) { return touch; }
virtual bool WantsTextInput() const { return false; }
protected:
int GetRequesterToken();
+1
View File
@@ -75,6 +75,7 @@ public:
virtual UI::Margins RootMargins() const { return UI::Margins(0); }
virtual void focusChanged(ScreenFocusChange focusChange) override {
Screen::focusChanged(focusChange);
modifiersPressed_ = Modifier::NONE;
}
+2
View File
@@ -50,6 +50,8 @@ public:
const char *tag() const override { return "CwCheat"; }
bool WantsTextInput() const override { return true; }
protected:
void BeforeCreateViews() override;
void CreateSettingsViews(UI::ViewGroup *) override;
+1
View File
@@ -52,6 +52,7 @@ public:
bool key(const KeyInput &touch) override;
bool WantsTextInput() const override { return true; }
protected:
ViewLayoutMode LayoutMode() const override { return ViewLayoutMode::IgnoreBottomInset; }
+4 -1
View File
@@ -325,6 +325,10 @@ void SearchBar::Draw(UIContext &dc) {
dc.DrawText(searchFilter_, bounds_.x + leftMargin, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER);
}
SearchBar::SearchBar(UI::LayoutParams *params) : UI::InertView(params) {
SetVisibility(UI::Visibility::V_GONE);
}
void SearchBar::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
w = 0;
h = 0;
@@ -439,7 +443,6 @@ bool ViewSearch::Key(UI::ViewGroup *viewGroup, const KeyInput &input) {
const int unichar = input.keyCode;
if (unichar >= 0x20 && unichar != 127) { // 127 gets produced from Ctrl+Backspace on Windows for some reason.
// TODO: Save focus state here.
// Insert it! (todo: do it with a string insert)
char buf[8];
buf[u8_wc_toutf8(buf, unichar)] = '\0';
+1 -1
View File
@@ -103,7 +103,7 @@ void AddRotationPicker(ScreenManager *screenManager, UI::ViewGroup *parent, bool
class SearchBar : public UI::InertView {
public:
SearchBar(UI::LayoutParams *params) : UI::InertView(params) { SetVisibility(UI::Visibility::V_GONE); }
SearchBar(UI::LayoutParams *params);
void Draw(UIContext &dc) override;
bool Touch(const TouchInput &input) override;