rename the selection search binding, unify into start_search action

This commit is contained in:
Mitchell Hashimoto
2026-01-06 14:08:34 -08:00
parent 9b6a3be993
commit 8e28f58b42
10 changed files with 15 additions and 84 deletions

View File

@@ -810,11 +810,6 @@ typedef struct {
ssize_t selected;
} ghostty_action_search_selected_s;
// apprt.action.SelectionForSearch
typedef struct {
const char* text;
} ghostty_action_selection_for_search_s;
// terminal.Scrollbar
typedef struct {
uint64_t total;
@@ -883,7 +878,6 @@ typedef enum {
GHOSTTY_ACTION_SHOW_ON_SCREEN_KEYBOARD,
GHOSTTY_ACTION_COMMAND_FINISHED,
GHOSTTY_ACTION_START_SEARCH,
GHOSTTY_ACTION_SELECTION_FOR_SEARCH,
GHOSTTY_ACTION_END_SEARCH,
GHOSTTY_ACTION_SEARCH_TOTAL,
GHOSTTY_ACTION_SEARCH_SELECTED,
@@ -925,7 +919,6 @@ typedef union {
ghostty_action_progress_report_s progress_report;
ghostty_action_command_finished_s command_finished;
ghostty_action_start_search_s start_search;
ghostty_action_selection_for_search_s selection_for_search;
ghostty_action_search_total_s search_total;
ghostty_action_search_selected_s search_selected;
ghostty_action_readonly_e readonly;

View File

@@ -616,7 +616,7 @@ class AppDelegate: NSObject,
syncMenuShortcut(config, action: "paste_from_selection", menuItem: self.menuPasteSelection)
syncMenuShortcut(config, action: "select_all", menuItem: self.menuSelectAll)
syncMenuShortcut(config, action: "start_search", menuItem: self.menuFind)
syncMenuShortcut(config, action: "selection_for_search", menuItem: self.menuSelectionForFind)
syncMenuShortcut(config, action: "search_selection", menuItem: self.menuSelectionForFind)
syncMenuShortcut(config, action: "search:next", menuItem: self.menuFindNext)
syncMenuShortcut(config, action: "search:previous", menuItem: self.menuFindPrevious)

View File

@@ -128,18 +128,6 @@ extension Ghostty.Action {
}
}
struct SelectionForSearch {
let text: String?
init(c: ghostty_action_selection_for_search_s) {
if let contentCString = c.text {
self.text = String(cString: contentCString)
} else {
self.text = nil
}
}
}
enum PromptTitle {
case surface
case tab

View File

@@ -621,9 +621,6 @@ extension Ghostty {
case GHOSTTY_ACTION_START_SEARCH:
startSearch(app, target: target, v: action.action.start_search)
case GHOSTTY_ACTION_SELECTION_FOR_SEARCH:
selectionForSearch(app, target: target, v: action.action.selection_for_search)
case GHOSTTY_ACTION_END_SEARCH:
endSearch(app, target: target)
@@ -1884,38 +1881,6 @@ extension Ghostty {
}
}
private static func selectionForSearch(
_ app: ghostty_app_t,
target: ghostty_target_s,
v: ghostty_action_selection_for_search_s
) {
switch (target.tag) {
case GHOSTTY_TARGET_APP:
Ghostty.logger.warning("selection_for_search does nothing with an app target")
return
case GHOSTTY_TARGET_SURFACE:
guard let surface = target.target.surface else { return }
guard let surfaceView = self.surfaceView(from: surface) else { return }
let selectionForSearch = Ghostty.Action.SelectionForSearch(c: v)
DispatchQueue.main.async {
if surfaceView.searchState != nil, let text = selectionForSearch.text {
NotificationCenter.default.post(
name: .ghosttySelectionForSearch,
object: surfaceView,
userInfo: [
"text": text
]
)
}
}
default:
assertionFailure()
}
}
private static func endSearch(
_ app: ghostty_app_t,
target: ghostty_target_s) {

View File

@@ -1521,7 +1521,7 @@ extension Ghostty {
@IBAction func selectionForFind(_ sender: Any?) {
guard let surface = self.surface else { return }
let action = "selection_for_search"
let action = "search_selection"
if (!ghostty_surface_binding_action(surface, action, UInt(action.lengthOfBytes(using: .utf8)))) {
AppDelegate.logger.warning("action failed action=\(action)")
}

View File

@@ -5163,12 +5163,12 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
);
},
.selection_for_search => {
.search_selection => {
const selection = try self.selectionString(self.alloc) orelse return false;
return try self.rt_app.performAction(
.{ .surface = self },
.selection_for_search,
.{ .text = selection },
.start_search,
.{ .needle = selection },
);
},

View File

@@ -316,9 +316,6 @@ pub const Action = union(Key) {
/// Start the search overlay with an optional initial needle.
start_search: StartSearch,
/// Input the selected text into the search field.
selection_for_search: SelectionForSearch,
/// End the search overlay, clearing the search state and hiding it.
end_search,
@@ -392,7 +389,6 @@ pub const Action = union(Key) {
show_on_screen_keyboard,
command_finished,
start_search,
selection_for_search,
end_search,
search_total,
search_selected,
@@ -919,17 +915,4 @@ pub const SearchSelected = struct {
}
};
pub const SelectionForSearch = struct {
text: [:0]const u8,
// Sync with: ghostty_action_selection_for_search_s
pub const C = extern struct {
text: [*:0]const u8,
};
pub fn cval(self: SelectionForSearch) C {
return .{
.text = self.text.ptr,
};
}
};

View File

@@ -6588,7 +6588,7 @@ pub const Keybinds = struct {
try self.set.putFlags(
alloc,
.{ .key = .{ .unicode = 'e' }, .mods = .{ .super = true } },
.selection_for_search,
.search_selection,
.{ .performable = true },
);
try self.set.putFlags(

View File

@@ -368,8 +368,10 @@ pub const Action = union(enum) {
/// If a previous search is active, it is replaced.
search: []const u8,
/// Input the selected text into the search field.
selection_for_search,
/// 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.
@@ -1287,7 +1289,7 @@ pub const Action = union(enum) {
.cursor_key,
.search,
.navigate_search,
.selection_for_search,
.search_selection,
.start_search,
.end_search,
.reset,

View File

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