Skip to content

fix(tasks): restore focus to the last used region on task re-entry#2931

Open
kchung wants to merge 2 commits into
generalaction:mainfrom
kchung:chung/fix-window-focus
Open

fix(tasks): restore focus to the last used region on task re-entry#2931
kchung wants to merge 2 commits into
generalaction:mainfrom
kchung:chung/fix-window-focus

Conversation

@kchung

@kchung kchung commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

Switching back to a task always focused the drawer terminal, even if you left off in the chat composer: both autofocus on task activation and the terminal wins.

Task views now remember which region owned focus (main panes vs terminal drawer) and restore it on re-entry. Autofocus effects gate on that region and skip when the user is already in a typing surface (shouldSkipAutofocus, rationale in its doc comment).

Related issues

Fixes #2930

Testing

  • 10 new tests covering the skip logic and snapshot restore
  • Manual dev build: task switching, drawer open/close, dragging a terminal to a main pane, clicking into inputs

Screenshot/Recording (if applicable)

Screen.Recording.2026-07-20.at.3.01.39.PM.mov
Checklist
  • I kept this PR small and focused
  • I ran a self-review before opening this PR
  • I ran the relevant local checks or explained why not
  • I updated docs when behavior or setup changed
  • I added or updated tests when behavior changed, or explained why not
  • I only added comments where the logic is not obvious
  • I used Conventional Commits for commit messages and, when possible, the PR title

Task views now remember whether the main panes or the terminal drawer
owned focus and restore that region when the task becomes active again,
instead of the drawer terminal always winning the autofocus race.

Autofocus effects gate on the remembered region and skip via
shouldSkipAutofocus when the user is already in a typing surface in the
same region, so passive region flips never steal focus. Stale snapshots
with a closed drawer but a 'bottom' region normalize back to 'main'.

Fixes generalaction#2930 (switching back to a task always focuses the terminal drawer)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kchung
kchung marked this pull request as ready for review July 20, 2026 22:14
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR restores the last focused task region when users return to a task. The main changes are:

  • Tracks focus between the main panes and terminal drawer.
  • Gates browser, chat, editor, and terminal autofocus by region.
  • Preserves focused-region state in task snapshots.
  • Adds focus handling for browser webviews and terminal moves.
  • Adds tests for focus suppression and snapshot restoration.

Confidence Score: 5/5

The latest changes look safe to merge.

  • No additional blocking issues were found in the updated code.

Important Files Changed

Filename Overview
apps/emdash-desktop/src/renderer/lib/region-focus.ts Adds shared logic for preventing autofocus from replacing focus on an active typing surface.
apps/emdash-desktop/src/renderer/features/tasks/stores/workspace-view-model.tsx Tracks the focused task region and restores valid focus state from task snapshots.
apps/emdash-desktop/src/renderer/features/tasks/view/task-main-column.tsx Marks task focus regions and updates focus ownership during pane interaction and terminal moves.
apps/emdash-desktop/src/renderer/features/browser/browser-toolbar.tsx Prevents deferred URL autofocus from replacing focus on an active typing surface.

Reviews (2): Last reviewed commit: "fix(tasks): ignore hidden active element..." | Re-trigger Greptile

Comment thread apps/emdash-desktop/src/renderer/lib/region-focus.ts
A hidden element can linger as document.activeElement when a view is
hidden instead of unmounted; it is not a place the user can type, so it
must not suppress autofocus. Feature-detected since jsdom lacks
checkVisibility.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kchung

kchung commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@greptile review

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.

[bug]: Switching back to a task always focuses the terminal drawer

1 participant