Skip to content

Commit b933d99

Browse files
Added global search keyboard shortcut
1 parent 688dc84 commit b933d99

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

CodeEdit/Features/Documents/Controllers/CodeEditWindowController.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
143143
}
144144
}
145145

146+
/// Opens the search navigator and focuses the search field
147+
@IBAction func openSearchNavigator(_ sender: Any? = nil) {
148+
if navigatorCollapsed {
149+
toggleFirstPanel()
150+
}
151+
152+
if let navigatorViewModel = navigatorSidebarViewModel,
153+
let searchTab = navigatorViewModel.tabItems.first(where: { $0 == .search }) {
154+
DispatchQueue.main.async {
155+
self.workspace?.searchState?.shouldFocusSearchField = true
156+
navigatorViewModel.setNavigatorTab(tab: searchTab)
157+
}
158+
}
159+
}
160+
146161
@IBAction func openQuickly(_ sender: Any?) {
147162
if let workspace, let state = workspace.openQuicklyViewModel {
148163
if let quickOpenPanel {

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extension WorkspaceDocument {
3535

3636
@Published var findNavigatorStatus: FindNavigatorStatus = .none
3737

38+
@Published var shouldFocusSearchField: Bool = false
39+
3840
unowned var workspace: WorkspaceDocument
3941
var tempSearchResults = [SearchResultModel]()
4042
var caseSensitive: Bool = false

CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorForm.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct FindNavigatorForm: View {
2525
@State private var preserveCase: Bool = false
2626
@State private var scopedToOpenEditors: Bool = false
2727
@State private var excludeSettings: Bool = true
28+
@FocusState private var isSearchFieldFocused: Bool
2829

2930
init(state: WorkspaceDocument.SearchState) {
3031
self.state = state
@@ -152,6 +153,7 @@ struct FindNavigatorForm: View {
152153
},
153154
hasValue: caseSensitive
154155
)
156+
.focused($isSearchFieldFocused)
155157
.onSubmit {
156158
if !state.searchQuery.isEmpty {
157159
Task {
@@ -262,6 +264,12 @@ struct FindNavigatorForm: View {
262264
}
263265
}
264266
}
267+
.onReceive(state.$shouldFocusSearchField) { shouldFocus in
268+
if shouldFocus {
269+
isSearchFieldFocused = true
270+
state.shouldFocusSearchField = false
271+
}
272+
}
265273
.lineLimit(1...5)
266274
}
267275
}

CodeEdit/Features/WindowCommands/ViewCommands.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ struct ViewCommands: Commands {
3333
}
3434
.keyboardShortcut("p", modifiers: [.shift, .command])
3535

36+
Button("Open Search Navigator") {
37+
NSApp.sendAction(#selector(CodeEditWindowController.openSearchNavigator(_:)), to: nil, from: nil)
38+
}
39+
.keyboardShortcut("f", modifiers: [.shift, .command])
40+
3641
Menu("Font Size") {
3742
Button("Increase") {
3843
if editorFontSize < 288 {

0 commit comments

Comments
 (0)