Focus Welcome search with Command-F
This commit is contained in:
1 parent
0b5e6d463f
commit
b73c3d3bc0
3 files changed
+38
-4
No files matched your search
@@ -239,6 +239,10 @@ final class WindowModel {
|
||||
/// doing nothing.
|
||||
private(set) var findFocusRequest: UInt64 = 0
|
||||
|
||||
/// Bumped by ⌘F while Welcome is in front. Welcome owns a large search
|
||||
/// field in its content instead of borrowing the titlebar Find field.
|
||||
private(set) var welcomeSearchFocusRequest: UInt64 = 0
|
||||
|
||||
/// True while the titlebar Find field owns the keyboard.
|
||||
///
|
||||
/// The field is outside every pane, but what it filters is inside one — so
|
||||
@@ -284,7 +288,12 @@ final class WindowModel {
|
||||
}
|
||||
}
|
||||
|
||||
var canFindInMainContent: Bool { findKind != nil }
|
||||
private var hasWelcomeSearch: Bool {
|
||||
guard case .vault = selectedDestination else { return false }
|
||||
return vaultDestination == .welcome
|
||||
}
|
||||
|
||||
var canFindInMainContent: Bool { hasWelcomeSearch || findKind != nil }
|
||||
|
||||
/// ⌘F. Focuses the titlebar field, and for a terminal also starts Ghostty's
|
||||
/// search again on a query retained from last time.
|
||||
@@ -295,6 +304,10 @@ final class WindowModel {
|
||||
/// field and the rebuild it caused takes the caret straight back, which is
|
||||
/// how the Find menu item came to be clickable and yet do nothing.
|
||||
func focusToolbarFind() {
|
||||
if hasWelcomeSearch {
|
||||
welcomeSearchFocusRequest &+= 1
|
||||
return
|
||||
}
|
||||
guard findKind != nil else { return }
|
||||
isToolbarFindFocused = true
|
||||
if findKind == .terminal { focusedSSHSession?.presentFind() }
|
||||
|
||||
@@ -821,6 +821,9 @@ struct WelcomeView: View {
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(.background)
|
||||
.onAppear { isSearchFocused = true }
|
||||
.onChange(of: window.welcomeSearchFocusRequest) { _, _ in
|
||||
isSearchFocused = true
|
||||
}
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
|
||||
@@ -38,10 +38,27 @@ struct WindowToolbarFindTests {
|
||||
window.openPage(.welcome)
|
||||
|
||||
#expect(window.findKind == nil)
|
||||
#expect(!window.canFindInMainContent)
|
||||
#expect(window.canFindInMainContent)
|
||||
#expect(window.creationActions.isEmpty)
|
||||
}
|
||||
|
||||
/// Welcome participates in the window-level Find command without growing a
|
||||
/// second search field in the titlebar.
|
||||
@Test
|
||||
func focusingFindOnWelcomeRequestsItsContentSearchField() {
|
||||
let window = WindowModel()
|
||||
var titlebarFocusRequests = 0
|
||||
window.focusToolbarFindField = { titlebarFocusRequests += 1 }
|
||||
window.openPage(.welcome)
|
||||
|
||||
window.focusToolbarFind()
|
||||
|
||||
#expect(window.welcomeSearchFocusRequest == 1)
|
||||
#expect(window.findFocusRequest == 0)
|
||||
#expect(!window.isToolbarFindFocused)
|
||||
#expect(titlebarFocusRequests == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
func assistantResolvesToConversationSearch() {
|
||||
let window = WindowModel()
|
||||
@@ -74,6 +91,7 @@ struct WindowToolbarFindTests {
|
||||
let window = WindowModel(workspaces: [Workspace(pane: Pane(.empty))])
|
||||
|
||||
#expect(window.findKind == nil)
|
||||
#expect(!window.canFindInMainContent)
|
||||
#expect(window.creationActions.isEmpty)
|
||||
}
|
||||
|
||||
@@ -98,12 +116,12 @@ struct WindowToolbarFindTests {
|
||||
/// counter nobody is watching.
|
||||
@Test
|
||||
func focusingFindIsANoOpWhereThereIsNoField() {
|
||||
let window = WindowModel()
|
||||
window.openPage(.welcome)
|
||||
let window = WindowModel(workspaces: [Workspace(pane: Pane(.empty))])
|
||||
|
||||
window.focusToolbarFind()
|
||||
|
||||
#expect(window.findFocusRequest == 0)
|
||||
#expect(window.welcomeSearchFocusRequest == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user