diff --git a/src/Surface.zig b/src/Surface.zig index 9998922b9..4103b91fb 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -5221,6 +5221,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool .search_selection => { const selection = try self.selectionString(self.alloc) orelse return false; + defer self.alloc.free(selection); return try self.rt_app.performAction( .{ .surface = self }, .start_search, diff --git a/src/apprt/gtk/class/application.zig b/src/apprt/gtk/class/application.zig index 848aa22db..bc83c09a4 100644 --- a/src/apprt/gtk/class/application.zig +++ b/src/apprt/gtk/class/application.zig @@ -734,7 +734,7 @@ pub const Application = extern struct { .show_on_screen_keyboard => return Action.showOnScreenKeyboard(target), .command_finished => return Action.commandFinished(target, value), - .start_search => Action.startSearch(target), + .start_search => Action.startSearch(target, value), .end_search => Action.endSearch(target), .search_total => Action.searchTotal(target, value), .search_selected => Action.searchSelected(target, value), @@ -2439,17 +2439,17 @@ const Action = struct { } } - pub fn startSearch(target: apprt.Target) void { + pub fn startSearch(target: apprt.Target, value: apprt.action.StartSearch) void { switch (target) { .app => {}, - .surface => |v| v.rt_surface.surface.setSearchActive(true), + .surface => |v| v.rt_surface.surface.setSearchActive(true, value.needle), } } pub fn endSearch(target: apprt.Target) void { switch (target) { .app => {}, - .surface => |v| v.rt_surface.surface.setSearchActive(false), + .surface => |v| v.rt_surface.surface.setSearchActive(false, ""), } } diff --git a/src/apprt/gtk/class/search_overlay.zig b/src/apprt/gtk/class/search_overlay.zig index 4936cd967..a81115462 100644 --- a/src/apprt/gtk/class/search_overlay.zig +++ b/src/apprt/gtk/class/search_overlay.zig @@ -250,6 +250,13 @@ pub const SearchOverlay = extern struct { priv.active = active; } + // Set contents of search + pub fn setSearchContents(self: *Self, content: [:0]const u8) void { + const priv = self.private(); + priv.search_entry.as(gtk.Editable).setText(content); + signals.@"search-changed".impl.emit(self, null, .{content}, null); + } + /// Set the total number of search matches. pub fn setSearchTotal(self: *Self, total: ?usize) void { const priv = self.private(); diff --git a/src/apprt/gtk/class/surface.zig b/src/apprt/gtk/class/surface.zig index 0d6c64433..d1eb144e9 100644 --- a/src/apprt/gtk/class/surface.zig +++ b/src/apprt/gtk/class/surface.zig @@ -2091,7 +2091,7 @@ pub const Surface = extern struct { self.as(gobject.Object).notifyByPspec(properties.@"error".impl.param_spec); } - pub fn setSearchActive(self: *Self, active: bool) void { + pub fn setSearchActive(self: *Self, active: bool, needle: [:0]const u8) void { const priv = self.private(); var value = gobject.ext.Value.newFrom(active); defer value.unset(); @@ -2101,6 +2101,10 @@ pub const Surface = extern struct { &value, ); + if (!std.mem.eql(u8, needle, "")) { + priv.search_overlay.setSearchContents(needle); + } + if (active) { priv.search_overlay.grabFocus(); }