Repository navigation
Add browser find focus debug logs #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
726f3a5
Add browser find focus debug logs
lawrencecchen afc5786
Allow browser find bar focus in portal host
lawrencecchen eeed8ab
Add split and terminal find debug logs
lawrencecchen 81ceee1
Avoid stealing search focus across splits
lawrencecchen 4fa48b2
Generalize panel focus restore intent
lawrencecchen 7cb165f
Unify split focus intent activation
lawrencecchen 49dc0e4
Address focus restore review feedback
lawrencecchen 76adeff
Yield inactive panel focus before restore
lawrencecchen 071704b
Gate browser find focus retries by generation
lawrencecchen 0a5473f
Avoid repeated browser focus invalidation
lawrencecchen 579d18f
Keep browser find ownership while find bar is open
lawrencecchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1398,15 +1398,10 @@ struct ContentView: View { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private enum CommandPaletteRestoreFocusIntent { | ||||||
| case panel | ||||||
| case browserAddressBar | ||||||
| } | ||||||
|
|
||||||
| private struct CommandPaletteRestoreFocusTarget { | ||||||
| let workspaceId: UUID | ||||||
| let panelId: UUID | ||||||
| let intent: CommandPaletteRestoreFocusIntent | ||||||
| let intent: PanelFocusIntent | ||||||
| } | ||||||
|
|
||||||
| private enum CommandPaletteInputFocusTarget { | ||||||
|
|
@@ -5337,7 +5332,7 @@ struct ContentView: View { | |||||
| static func shouldRestoreBrowserAddressBarAfterCommandPaletteDismiss( | ||||||
| focusedPanelIsBrowser: Bool, | ||||||
| focusedBrowserAddressBarPanelId: UUID?, | ||||||
| focusedPanelId: UUID | ||||||
| focusedPanelId: UUID? | ||||||
| ) -> Bool { | ||||||
| focusedPanelIsBrowser && focusedBrowserAddressBarPanelId == focusedPanelId | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: When both optional UUIDs are Prompt for AI agents
Suggested change
|
||||||
| } | ||||||
|
|
@@ -5383,15 +5378,10 @@ struct ContentView: View { | |||||
|
|
||||||
| private func presentCommandPalette(initialQuery: String) { | ||||||
| if let panelContext = focusedPanelContext { | ||||||
| let shouldRestoreBrowserAddressBar = Self.shouldRestoreBrowserAddressBarAfterCommandPaletteDismiss( | ||||||
| focusedPanelIsBrowser: panelContext.panel.panelType == .browser, | ||||||
| focusedBrowserAddressBarPanelId: AppDelegate.shared?.focusedBrowserAddressBarPanelId(), | ||||||
| focusedPanelId: panelContext.panelId | ||||||
| ) | ||||||
| commandPaletteRestoreFocusTarget = CommandPaletteRestoreFocusTarget( | ||||||
| workspaceId: panelContext.workspace.id, | ||||||
| panelId: panelContext.panelId, | ||||||
| intent: shouldRestoreBrowserAddressBar ? .browserAddressBar : .panel | ||||||
| intent: panelContext.panel.captureFocusIntent(in: observedWindow) | ||||||
| ) | ||||||
| } else { | ||||||
| commandPaletteRestoreFocusTarget = nil | ||||||
|
|
@@ -5468,7 +5458,7 @@ struct ContentView: View { | |||||
| if let clickedFocusTarget { | ||||||
| dlog( | ||||||
| "palette.dismiss.backdrop focusTarget panel=\(clickedFocusTarget.panelId.uuidString.prefix(5)) " + | ||||||
| "workspace=\(clickedFocusTarget.workspaceId.uuidString.prefix(5)) intent=\(clickedFocusTarget.intent == .browserAddressBar ? "addressBar" : "panel")" | ||||||
| "workspace=\(clickedFocusTarget.workspaceId.uuidString.prefix(5)) intent=\(debugCommandPaletteFocusIntent(clickedFocusTarget.intent))" | ||||||
| ) | ||||||
| } else { | ||||||
| dlog("palette.dismiss.backdrop focusTarget=nil") | ||||||
|
|
@@ -5507,10 +5497,11 @@ struct ContentView: View { | |||||
| let workspaceId = terminalView.tabId, | ||||||
| let panelId = terminalView.terminalSurface?.id, | ||||||
| tabManager.tabs.contains(where: { $0.id == workspaceId }) { | ||||||
| return CommandPaletteRestoreFocusTarget( | ||||||
| return commandPaletteRestoreFocusTarget( | ||||||
| workspaceId: workspaceId, | ||||||
| panelId: panelId, | ||||||
| intent: .panel | ||||||
| fallbackIntent: .terminal(.surface), | ||||||
| in: window | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -5522,10 +5513,11 @@ struct ContentView: View { | |||||
| let workspaceId = terminalView.tabId, | ||||||
| let panelId = terminalView.terminalSurface?.id, | ||||||
| tabManager.tabs.contains(where: { $0.id == workspaceId }) { | ||||||
| return CommandPaletteRestoreFocusTarget( | ||||||
| return commandPaletteRestoreFocusTarget( | ||||||
| workspaceId: workspaceId, | ||||||
| panelId: panelId, | ||||||
| intent: .panel | ||||||
| fallbackIntent: .terminal(.surface), | ||||||
| in: observedWindow | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -5563,16 +5555,35 @@ struct ContentView: View { | |||||
| continue | ||||||
| } | ||||||
|
|
||||||
| return CommandPaletteRestoreFocusTarget( | ||||||
| return commandPaletteRestoreFocusTarget( | ||||||
| workspaceId: workspace.id, | ||||||
| panelId: panelId, | ||||||
| intent: .panel | ||||||
| fallbackIntent: .browser(.webView), | ||||||
| in: observedWindow | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| private func commandPaletteRestoreFocusTarget( | ||||||
| workspaceId: UUID, | ||||||
| panelId: UUID, | ||||||
| fallbackIntent: PanelFocusIntent, | ||||||
| in window: NSWindow? | ||||||
| ) -> CommandPaletteRestoreFocusTarget { | ||||||
| let intent = tabManager.tabs | ||||||
| .first(where: { $0.id == workspaceId })? | ||||||
| .panels[panelId]? | ||||||
| .captureFocusIntent(in: window) ?? fallbackIntent | ||||||
|
|
||||||
| return CommandPaletteRestoreFocusTarget( | ||||||
| workspaceId: workspaceId, | ||||||
| panelId: panelId, | ||||||
| intent: intent | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| private func restoreCommandPaletteFocus( | ||||||
| target: CommandPaletteRestoreFocusTarget, | ||||||
| attemptsRemaining: Int | ||||||
|
|
@@ -5588,8 +5599,9 @@ struct ContentView: View { | |||||
| if let context = focusedPanelContext, | ||||||
| context.workspace.id == target.workspaceId, | ||||||
| context.panelId == target.panelId { | ||||||
| restoreCommandPaletteInputFocusIfNeeded(target: target, attemptsRemaining: 6) | ||||||
| return | ||||||
| if context.panel.restoreFocusIntent(target.intent) { | ||||||
| return | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| guard attemptsRemaining > 0 else { return } | ||||||
|
|
@@ -5598,33 +5610,32 @@ struct ContentView: View { | |||||
| if let context = focusedPanelContext, | ||||||
| context.workspace.id == target.workspaceId, | ||||||
| context.panelId == target.panelId { | ||||||
| restoreCommandPaletteInputFocusIfNeeded(target: target, attemptsRemaining: 6) | ||||||
| return | ||||||
| if context.panel.restoreFocusIntent(target.intent) { | ||||||
| return | ||||||
| } | ||||||
| } | ||||||
| restoreCommandPaletteFocus(target: target, attemptsRemaining: attemptsRemaining - 1) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private func restoreCommandPaletteInputFocusIfNeeded( | ||||||
| target: CommandPaletteRestoreFocusTarget, | ||||||
| attemptsRemaining: Int | ||||||
| ) { | ||||||
| guard !isCommandPalettePresented else { return } | ||||||
| guard target.intent == .browserAddressBar else { return } | ||||||
| guard attemptsRemaining > 0 else { return } | ||||||
| guard let appDelegate = AppDelegate.shared else { return } | ||||||
|
|
||||||
| if appDelegate.requestBrowserAddressBarFocus(panelId: target.panelId) { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| DispatchQueue.main.asyncAfter(deadline: .now() + 0.03) { | ||||||
| restoreCommandPaletteInputFocusIfNeeded( | ||||||
| target: target, | ||||||
| attemptsRemaining: attemptsRemaining - 1 | ||||||
| ) | ||||||
| #if DEBUG | ||||||
| private func debugCommandPaletteFocusIntent(_ intent: PanelFocusIntent) -> String { | ||||||
| switch intent { | ||||||
| case .panel: | ||||||
| return "panel" | ||||||
| case .terminal(.surface): | ||||||
| return "terminal.surface" | ||||||
| case .terminal(.findField): | ||||||
| return "terminal.findField" | ||||||
| case .browser(.webView): | ||||||
| return "browser.webView" | ||||||
| case .browser(.addressBar): | ||||||
| return "browser.addressBar" | ||||||
| case .browser(.findField): | ||||||
| return "browser.findField" | ||||||
| } | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| private func resetCommandPaletteSearchFocus() { | ||||||
| applyCommandPaletteInputFocusPolicy(.search) | ||||||
|
|
||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSTextView.delegateis an unsafe-unretained AppKit property, so reading it during responder teardown can crash with an unowned-reference trap; this helper now does that on every browser find-overlay log path. Since overlay mount/remove frequently coincides with first-responder churn, this reintroduces the exact crash pattern already called out elsewhere in the codebase (see the guard comment inAppDelegatearound field-editor delegate access).Useful? React with 👍 / 👎.