emdash icon indicating copy to clipboard operation
emdash copied to clipboard

fix(tasks): keep agent input focused after sidebar switch

Open janburzinski opened this issue 5 months ago โ€ข 5 comments

Description

  • keep agent input focused after switching back to conversation in sidebar
  • refocuses the active conversation pty onyl when main content has focus
Checklist
  • [X] I kept this PR small and focused
  • [X] I ran a self-review before opening this PR
  • [X] I ran the relevant local checks or explained why not
  • [X] I updated docs when behavior or setup changed
  • [X] I added or updated tests when behavior changed, or explained why not
  • [X] I only added comments where the logic is not obvious
  • [X] I used Conventional Commits for commit messages and, when possible, the PR title

janburzinski avatar Jun 15 '26 12:06 janburzinski

Greptile Summary

This PR restores focus to the active conversation's PTY terminal whenever the user switches back to the conversations sidebar tab, but only when the main content region is active โ€” ensuring the terminal drawer's own focus state is never stolen.

  • Adds a private focusActiveConversationTerminal method that walks conversationRegistry โ†’ sessions โ†’ pty โ†’ terminal.focus() via optional chaining, with an early-exit guard for a missing active conversation ID.
  • setSidebarTab now calls the helper only when v === 'conversations' && focusedRegion === 'main', keeping the guard logic co-located with the tab-switch side effect.
  • A new test verifies both the focus path (focusedRegion === 'main') and the no-focus path (focusedRegion === 'bottom') in a single, well-structured scenario.

Confidence Score: 5/5

Safe to merge โ€” the change is minimal, well-guarded, and directly tested.

The new code path is a single conditional inside setSidebarTab with optional-chaining throughout, so a missing registry entry or null PTY session degrades gracefully to a no-op. The focusedRegion guard is exercised by the new test, which confirms focus is called exactly once on the happy path and not at all when the terminal drawer has focus.

No files require special attention.

Important Files Changed

Filename Overview
apps/emdash-desktop/src/renderer/features/tasks/stores/workspace-view-model.tsx Adds a private focusActiveConversationTerminal helper and calls it from setSidebarTab when switching to conversations only if focusedRegion === 'main'. Logic is tight and the guard correctly prevents stealing focus from the terminal drawer.
apps/emdash-desktop/src/renderer/features/tasks/stores/workspace-view-model.test.ts New test covers both the happy path (focus called when switching to conversations with main focused) and the guard (focus not called when bottom region is focused). Clean setup and teardown with dispose() at the end.

Sequence Diagram

sequenceDiagram
    participant User
    participant Sidebar
    participant WorkspaceViewModel
    participant ConversationRegistry
    participant PtyTerminal

    User->>Sidebar: click "conversations" tab
    Sidebar->>WorkspaceViewModel: setSidebarTab('conversations')
    WorkspaceViewModel->>WorkspaceViewModel: "sidebarTab = 'conversations'"
    alt "focusedRegion === 'main'"
        WorkspaceViewModel->>WorkspaceViewModel: focusActiveConversationTerminal()
        WorkspaceViewModel->>ConversationRegistry: get(taskId)?.sessions.get(conversationId)
        ConversationRegistry-->>WorkspaceViewModel: PtySession
        WorkspaceViewModel->>PtyTerminal: terminal.focus()
    else "focusedRegion === 'bottom'"
        WorkspaceViewModel-->>Sidebar: (no focus action)
    end

Reviews (2): Last reviewed commit: "fix(tasks): guard conversation terminal ..." | Re-trigger Greptile

greptile-apps avatar Jun 15 '26 12:06 greptile-apps

@greptileai

janburzinski avatar Jun 15 '26 12:06 janburzinski

Thanks for catching this and for the fix, @janburzinski small screen recording would help next time ๐Ÿ™

arnestrickmann avatar Jun 15 '26 19:06 arnestrickmann

happy to merge after recording:)

arnestrickmann avatar Jun 16 '26 01:06 arnestrickmann

before: https://streamable.com/xeygn1

after: https://streamable.com/swjxdw

again my bad, but here is the demo :D @arnestrickmann

janburzinski avatar Jun 16 '26 12:06 janburzinski

lgtm!

arnestrickmann avatar Jun 16 '26 21:06 arnestrickmann