Prevent hiding SearchEntry on search-stop signal

Hello.
I have a SearchEntry inside SearchBar and put it into the title widget of HeaderBar.
Every time Esc is pressed, the search entry disapears (there is a Revealer up there in the tree, which hides the entry widget).
Is it possible to prevent that? And why such behaviour exists by default?
Erasing the search term is ok, but why hide widget itself?
Docs says
stop-search signal Emitted when the user stops a search via keyboard input. This is a keybinding signal. Applications should connect to it, to implement hiding the search entry in this case. The default bindings for this signal is Escape.
I can connect to stop-search signal, but what to do next? How to prevent search entry widget hiding?

This is the default behaviour when you place a Gtk.SearchEntry in a Gtk.SearchBar, since that’s sort of the whole point of the search bar widget.

If for some reason you want to use a Gtk.SearchBar and not hide on Esc, I guess you could connect to Gtk.SearchEntry::stop-search before adding it to the search bar and call GObject.signal_stop_emission() to prevent the handler from hiding the revealer:

static void
on_stop_search (GtkSearchEntry *entry,
                gpointer        user_data)
{
  g_object_signal_stop_emission (G_OBJECT (entry));
}

That also means that any other handlers connected to the signal will not be invoked, though. I’m not sure if that’s the best way to do what you want, but I think it’s sort of the expected behaviour from this widget for users :person_shrugging:

1 Like

it works, thank you!

1 Like