Add a configurable "Re-detect Focus" reload action#4
Open
t-h-tech wants to merge 1 commit into
Open
Conversation
Cotabby sometimes latches onto the wrong focus source — keeping a plain AX text field (e.g. an editor pane) instead of the terminal shell prompt or the Claude Code TUI — because the editor-protection guards key off a cached focus snapshot that can go stale. This adds a manual escape hatch plus a low-risk automatic mitigation. - Reload action: discards stale terminal/TUI injections and cached AX state, prunes dead shell sessions, drops stale prompt anchors, re-reads the focused element, and re-evaluates suggestion availability. - Configurable global hotkey, opt-in / unbound by default, set in Settings -> Shortcuts, plus a "Re-detect Focus" menu-bar item. - Auto-refresh focus on app activation so switching into a terminal/editor dissolves a stale snapshot without a manual reload. Adds keybind storage + conflict-detection test coverage.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Cotabby sometimes latches onto the wrong focus source — it keeps a plain AX text field (e.g. an editor pane) instead of the terminal shell prompt or the Claude Code TUI, because the editor-protection guards key off a focus snapshot that can go stale. This adds a manual escape hatch (a configurable "Re-detect Focus" reload action, available as both a global hotkey and a menu-bar item) plus a low-risk automatic mitigation (re-read focus on app activation).
What the reload does, in order: prune dead shell sessions → cancel in-flight TUI OCR and release a TUI-owned injection → stop AX suppression and republish the real focused element → drop stale prompt anchors → force an immediate fresh AX read → re-evaluate suggestion availability. After that, the next shell report / TUI heartbeat / keystroke re-injects the correct source because the stale snapshot that was blocking it is gone.
Validation
Manual: built + ran from Xcode; bound the hotkey in Settings → Shortcuts, confirmed it fires the reload, and confirmed the menu-bar "Re-detect Focus" item triggers the same path. App-activation auto-refresh re-resolves the focused source when switching back into a terminal/editor pane without pressing reload.
Linked issues
None.
Risk / rollout notes
UserDefaultskeys (cotabbyReloadFocusKeyCode/Modifiers/Label), all defaulting to the disabled sentinel. No existing keys touched.FocusTrackerdebounces by focused-element identity, so this is cheap. The observer is owned byAppDelegate(app-lifetime), not the transient environment.Cotabby.xcodeproj/project.pbxprojwas regenerated withxcodegen generateto wire in the new test (the only change is the four standard entries forReloadFocusKeybindTests.swift; no signing/team or other drift).