apprt/gtk: enter/shift+enter for traversing search results

pull/9756/head
Mitchell Hashimoto 2025-11-29 20:20:38 -08:00
parent 72b3c14833
commit f7a6822e30
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
2 changed files with 28 additions and 0 deletions

View File

@ -2,6 +2,7 @@ const std = @import("std");
const adw = @import("adw");
const glib = @import("glib");
const gobject = @import("gobject");
const gdk = @import("gdk");
const gtk = @import("gtk");
const gresource = @import("../build/gresource.zig");
@ -204,6 +205,26 @@ pub const SearchOverlay = extern struct {
signals.@"previous-match".impl.emit(self, null, .{}, null);
}
fn searchEntryKeyPressed(
_: *gtk.EventControllerKey,
keyval: c_uint,
_: c_uint,
gtk_mods: gdk.ModifierType,
self: *Self,
) callconv(.c) c_int {
if (keyval == gdk.KEY_Return or keyval == gdk.KEY_KP_Enter) {
if (gtk_mods.shift_mask) {
signals.@"previous-match".impl.emit(self, null, .{}, null);
} else {
signals.@"next-match".impl.emit(self, null, .{}, null);
}
return 1;
}
return 0;
}
//---------------------------------------------------------------
// Virtual methods
@ -262,6 +283,7 @@ pub const SearchOverlay = extern struct {
class.bindTemplateCallback("match_label_closure", &closureMatchLabel);
class.bindTemplateCallback("next_match", &nextMatch);
class.bindTemplateCallback("previous_match", &previousMatch);
class.bindTemplateCallback("search_entry_key_pressed", &searchEntryKeyPressed);
// Properties
gobject.ext.registerProperties(class, &.{

View File

@ -25,6 +25,12 @@ template $GhosttySearchOverlay: Adw.Bin {
search-changed => $search_changed();
next-match => $next_match();
previous-match => $previous_match();
EventControllerKey {
// We need this so we capture before the SearchEntry.
propagation-phase: capture;
key-pressed => $search_entry_key_pressed();
}
}
Label {