macOS: Selection for Find feature (#10192)

Adds the `selection_for_search` action, with Cmd+E keybind by default.
This action inputs the currently selected text into the search field
without changing focus, matching standard macOS behavior.

Implements discussion #9776 and #10036

<details><summary>AI Disclosure</summary>
<p>

Tab completions with Codestral.
Reviewed by Gemini 3 Flash via chatting.
No Agentic coding tools were involved.

</p>
</details>
This commit is contained in:
Mitchell Hashimoto
2026-01-06 14:26:03 -08:00
committed by GitHub
12 changed files with 65 additions and 8 deletions

View File

@@ -5163,6 +5163,15 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
);
},
.search_selection => {
const selection = try self.selectionString(self.alloc) orelse return false;
return try self.rt_app.performAction(
.{ .surface = self },
.start_search,
.{ .needle = selection },
);
},
.end_search => {
// We only return that this was performed if we actually
// stopped a search, but we also send the apprt end_search so

View File

@@ -313,7 +313,9 @@ pub const Action = union(Key) {
/// A command has finished,
command_finished: CommandFinished,
/// Start the search overlay with an optional initial needle.
/// Start the search overlay with an optional initial needle. If the
/// search is already active and the needle is non-empty, update the
/// current search needle and focus the search input.
start_search: StartSearch,
/// End the search overlay, clearing the search state and hiding it.

View File

@@ -6585,6 +6585,12 @@ pub const Keybinds = struct {
.start_search,
.{ .performable = true },
);
try self.set.putFlags(
alloc,
.{ .key = .{ .unicode = 'e' }, .mods = .{ .super = true } },
.search_selection,
.{ .performable = true },
);
try self.set.putFlags(
alloc,
.{ .key = .{ .unicode = 'f' }, .mods = .{ .super = true, .shift = true } },

View File

@@ -368,6 +368,11 @@ pub const Action = union(enum) {
/// If a previous search is active, it is replaced.
search: []const u8,
/// Start a search for the current text selection. If there is no
/// selection, this does nothing. If a search is already active, this
/// changes the search terms.
search_selection,
/// Navigate the search results. If there is no active search, this
/// is not performed.
navigate_search: NavigateSearch,
@@ -1284,6 +1289,7 @@ pub const Action = union(enum) {
.cursor_key,
.search,
.navigate_search,
.search_selection,
.start_search,
.end_search,
.reset,

View File

@@ -189,6 +189,12 @@ fn actionCommands(action: Action.Key) []const Command {
.description = "Start a search if one isn't already active.",
}},
.search_selection => comptime &.{.{
.action = .search_selection,
.title = "Search Selection",
.description = "Start a search for the current text selection.",
}},
.end_search => comptime &.{.{
.action = .end_search,
.title = "End Search",