diff --git a/include/ghostty.h b/include/ghostty.h index 726b368e7..5fc3a7433 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -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; diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index c365fb935..c0886607c 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -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) diff --git a/macos/Sources/Ghostty/Ghostty.Action.swift b/macos/Sources/Ghostty/Ghostty.Action.swift index c04c7d958..91f1491dd 100644 --- a/macos/Sources/Ghostty/Ghostty.Action.swift +++ b/macos/Sources/Ghostty/Ghostty.Action.swift @@ -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 diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index 69788c194..4e9166168 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -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) { diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift index 1fc43ac82..a5ba62571 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift @@ -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)") } diff --git a/src/Surface.zig b/src/Surface.zig index 68cf46045..1f3e4da8b 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -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 }, ); }, diff --git a/src/apprt/action.zig b/src/apprt/action.zig index 7fdaabf08..f00ab16ef 100644 --- a/src/apprt/action.zig +++ b/src/apprt/action.zig @@ -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, - }; - } -}; diff --git a/src/config/Config.zig b/src/config/Config.zig index 698831ec1..ef6132912 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -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( diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 0ef5208bc..08f5fdf7c 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -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, diff --git a/src/input/command.zig b/src/input/command.zig index 3fc7b29f6..d6d2b0247 100644 --- a/src/input/command.zig +++ b/src/input/command.zig @@ -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 &.{.{