Skip to content

fix(panel): hand focus to the source app on every open-editor path - #148

Merged
StuBehan merged 1 commit into
mainfrom
fix/open-editor-focus-handoff
Aug 8, 2026
Merged

fix(panel): hand focus to the source app on every open-editor path#148
StuBehan merged 1 commit into
mainfrom
fix/open-editor-focus-handoff

Conversation

@StuBehan

@StuBehan StuBehan commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Problem

"Open editor" (O / Enter on a stop event) sometimes leaves you looking at StackNudge instead of jumping to the source app. It worked intermittently, which read as flaky.

Cause

actOnSelected only hid the panel when the acted-on event was the last one in the list:

if sendApproval || event.fifoPath == nil {
    store.remove(id: event.id)
    if store.events.isEmpty { hidePanel() }   // only reachable here
}

Any time other events remained, AppActivator.activate was dispatched with the panel still up and StackNudge still active. The panel is .floating, hidesOnDeactivate = false, .canJoinAllSpaces, and panelDidResignKey's auto-hide is gated behind !panelPinned (pin defaults on), so nothing else pulled it down — the source app never came forward. Events have no TTL, so a non-empty list is the common case.

The three sibling focus paths all hide first: focusSelectedSession (hidePanel()), the banner-click handler (NSApp.hide + settle), and openConfig (orderOut). Only the events-tab path didn't.

Fix

  • actOnSelected: split the removal concern from the hide concern. Every path that hands focus to the source app (editor jump or approval keystroke) now hidePanel()s unconditionally, then settles 0.15s before AppActivator.activate so our deactivation lands before the target is raised. Blocking-permission O still keeps the event in the store (so it can be resolved later) but now hides too. Pure FIFO-approve keeps the panel up while other prompts remain (triage), closing only when the list empties — it doesn't jump anywhere.
  • focusSelectedSession: added the same 0.15s settle after its existing hidePanel().
  • AppActivator: the six NSAppleScript calls swallowed their error dicts. They now route through logScriptError, which prints to stderr under STACKNUDGE_PANEL_DEBUG (no-op otherwise). A missing Automation grant — wiped on every ad-hoc rebuild, and reset dozens of times in local logs — makes these calls silently no-op, which is a plausible second contributor; this makes the next occurrence diagnosable instead of invisible.

Verification

  • swiftc -typecheck panel+shared: exit 0 (only pre-existing deprecation warnings).
  • ./build.sh: exit 0.
  • Live-tested via make reload: injected 2+ events, pressed O on a non-last event — panel now hides and the source window comes forward. Previously it stayed up.

@StuBehan
StuBehan merged commit 09ea677 into main Aug 8, 2026
6 checks passed
@StuBehan
StuBehan deleted the fix/open-editor-focus-handoff branch August 8, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant