only notify search change when widget was inactive

pull/9766/head
rhodes-b 2025-11-30 21:06:25 -06:00
parent 2a9a57daff
commit 3ab49fdb5f
2 changed files with 18 additions and 4 deletions

View File

@ -223,6 +223,13 @@ pub const SearchOverlay = extern struct {
gtk.Widget.initTemplate(self.as(gtk.Widget));
}
/// Update search contents when widget is activated
pub fn updateSearch(self: *Self) void {
const priv = self.private();
const text = priv.search_entry.as(gtk.Editable).getText();
signals.@"search-changed".impl.emit(self, null, .{text}, null);
}
/// Grab focus on the search entry and select all text.
pub fn grabFocus(self: *Self) void {
const priv = self.private();
@ -231,10 +238,6 @@ pub const SearchOverlay = extern struct {
// Select all text in the search entry field. -1 is distance from
// the end, causing the entire text to be selected.
priv.search_entry.as(gtk.Editable).selectRegion(0, -1);
// update search state with the active text
const text = priv.search_entry.as(gtk.Editable).getText();
signals.@"search-changed".impl.emit(self, null, .{text}, null);
}
/// Set the total number of search matches.

View File

@ -1964,6 +1964,17 @@ pub const Surface = extern struct {
SearchOverlay.properties.active.name,
&value,
);
var is_active = gobject.ext.Value.newFrom(false);
defer is_active.unset();
gobject.Object.getProperty(
priv.search_overlay.as(gobject.Object),
SearchOverlay.properties.active.name,
&is_active
);
if (active and !is_active) {
priv.search_overlay.updateSearch();
}
if (active) {
priv.search_overlay.grabFocus();
}