Skip to content

fix(dialogs): Escape closes the dialog in front when two are open - #3053

Merged
devswha merged 3 commits into
mainfrom
fix/dialog-escape-stack
Nov 5, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/dialog-escape-stack

Conversation

@devswha

@devswha devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Fixes #3037. Follow-up to #3036.

Problem

Settings, Files and New workspace each close on their own window or document Escape listener. Those run in the order they were added, not in the order the dialogs are drawn, so with two dialogs open one Escape could close the dialog underneath and leave the one in front (the one with the keyboard) open:

  1. Settings open, then the palette's Browse files: Files opens over Settings and takes the focus. Escape closed Settings and left Files open (reproduced, as in the issue).
  2. New workspace open, then Settings with its shortcut: New workspace's document listener runs before Settings' window listener, so Escape closed New workspace and left Settings open. The issue had this from code reading only; it reproduces (the new regression step fails without the New workspace change). While a workspace was being created, it also took that Escape without closing.

Change

  • focusInOtherModal(surface) in src/lib/useFocusTrap.ts: the focus is inside another aria-modal surface. It is the check FilesDialog has done inline since fix(files): keep Escape closing Files when the key re-renders the app #3026; Files now calls the helper.
  • SettingsDialog and NewSessionDialog leave an Escape to the dialog that has the focus. Each Escape closes the dialog in front, and the one underneath closes on the next Escape.

This follows the WAI-ARIA modal dialog pattern that the Codex and Claude desktop apps also follow: Escape belongs to the dialog that has the focus. Every dialog opened inside Settings (Confirm, Connect phone, usage sign-in, row menus) already handles its own Escape and stops it, so none of them depended on Settings closing.

Validation

  • Failing first: bun run check run --build bun scripts/files-prompt-regression.ts with two new desktop steps (Files from the palette over Settings; Settings over New workspace). On origin/main the first step fails ("waiting for .files-dialog to be hidden"). With only the New workspace change removed, the second step fails (Settings stays open because New workspace closed instead). With the fix, 8/8 scenarios pass, also after rebasing on origin/main 02881f0.
  • bun run check fast on the rebased head: success (typecheck, build, 12289 unit tests, 0 failures).
  • Browser regressions, run in the CI runner image (herdr-ci-runner:local, ci-browser-parallel.ts, 6 workers) on the change before the rebase: 157/160 passed. I re-ran the 3 that failed side by side on origin/main 5b51cbe and on this change, in the same image: ui-contexts-regression and revision-bound-update-demo-regression pass on both (the first failures came from host load and a checkout whose git directory the container could not read). unconfirmed-input-demo-regression fails on both at the same line (:64, the terminal textarea wait), so it was already failing before this change.
  • bun test scripts/changelog-fold.test.ts: pass.
  • Skipped: bun run check full, Windows VM, Mac.

Settings, Files and New workspace each close on a window or document
Escape listener, which run in the order they were added, not the order
the dialogs are drawn in. Settings under Files opened from the palette
closed first and left Files, the dialog in front, open; New workspace
under Settings did the same. Each now leaves the Escape when the focus is
in another aria-modal surface (focusInOtherModal), as Files already did.

Fixes #3037
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8f45d86 and 25fba2c.

Files selected for processing: 6

  • changelog.d/dialog-escape-front-first.md
  • scripts/files-prompt-regression.ts
  • src/components/FilesDialog.tsx
  • src/components/NewSessionDialog.tsx
  • src/components/SettingsDialog.tsx
  • src/lib/useFocusTrap.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Settings is drawn over a file or diff preview, whose Escape waits while
Settings is open. A file opened from Files over Settings takes the focus,
so the focused-dialog check left that Escape to no one. Over a preview,
Settings takes the Escape as before (found by Codex review of #3053).
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review summary for head 25fba2c:

  • omo (dori review): CLEAR at 25fba2c.
  • Codex (gpt-6.1-terra, xhigh), first pass: one MEDIUM, reproduced and fixed in bb0b378. With a file opened from Files over Settings, Escape closed nothing, because Settings is drawn over the preview and the preview's Escape waits while Settings is open. Settings now keeps the Escape over a preview (overPreview). files-prompt-regression covers this case: it failed before the fix and passes after it.
  • Codex re-review of the fix round: no new regression from this PR. It reported one MEDIUM that already exists on origin/main, from code reading only (not reproduced): over a popup preview, a ConfirmDialog opened from Settings (About, Terminals, Switch) is portaled into the normal modal layer, so it may be drawn behind Settings, which is raised over the preview (SettingsDialog.css:4). Escape then closes that confirmation first. That is a layer-order question, not Escape order, and it is out of this PR's scope. I filed no follow-up issue because it has not been reproduced.
  • CodeRabbit is rate-limited and has not reviewed this head.

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate (owner-approved): bun run check fast passed at this head (12322/0), omo CLEAR at this exact head, Codex re-review found nothing this PR introduced, threads resolved, merges cleanly. The three new files-prompt steps fail before the fix; file-viewer, settings-pages, files-panel and diff-find pass. Fixes #3037. Merged without waiting for GitHub CI.

@devswha
devswha merged commit edb1765 into main Nov 5, 2026
10 of 11 checks passed
@devswha
devswha deleted the fix/dialog-escape-stack branch November 5, 2026 20:38
devswha added a commit that referenced this pull request Nov 5, 2026
Fixes #636.

## What

A new opt-in setting, **Settings > File viewer > Markdown outline** (off
by default, a device setting in its own storage key like the other
recent opt-ins). With it on, a Markdown Preview that has two headings or
more lists them:

- **Levels and repeated titles.** The outline lists the document's own
headings (not ones inside a quote), each level under the shallowest one
stepped in. A title written twice is two entries, and each goes to its
own heading.
- **Follows the reading.** As the document scrolls, the heading being
read (the last one past a line 32 px under the body's top) is marked
with the accent on a tint, and kept in the middle of the list. Only the
list scrolls to do that, so the browser clamps it at the list's start
and end, and the document's position and the keyboard focus never move
with it. At the very end of the document, the last heading in view is
marked (short final sections cannot reach the reading line).
- **Choosing an entry** brings its heading to 8 px under the top. A
chosen entry stays marked while the document rests where the choice left
it, even when the end of the document keeps the heading from reaching
the top.
- **Wide viewer** (body at least 760 px: the popup and the reader tab on
a desktop): a 240 px column after the document. The header's new
**Outline** button folds and unfolds it.
- **Narrow viewer** (a phone, the docked panel): nothing changes until
the **Outline** button (header; the toolbar when docked) is pressed. It
opens the outline as a drawer over the document's end edge, so the text
keeps its whole width. Opening the drawer centers the heading being read
and puts the focus on it. A choice, Escape (which closes the drawer
only, not the viewer) or a press outside closes it, and the focus
returns to the button.

With the setting off (the default), the viewer is unchanged: the body's
new wrapper is `display: contents`, so it lays nothing out. The wrapper
is always rendered so the body is never remounted when an outline
appears, which keeps its focus and scroll.

**Design reference:** Zed's outline panel (the current symbol is marked
and kept in view while the editor scrolls) for the column, and GitHub's
Markdown file outline button for the narrow drawer. There is a DESIGN.md
entry.

Compared with #651 (closed as a duplicate before the Markdown preview
landed): this builds on the preview that is on main now, adds only the
outline, and keeps it opt-in.

## Tests

- `scripts/markdown-outline-browser-qa.ts` (new, added to
`scripts/ci-browser.sh`): the real viewer built by Vite and served under
the app's CSP, light and dark.
- Off: no outline, no button, and the wrapper computes to `display:
contents`.
- 1280 popup: a column whose width plus the body's equals the row; 61
entries for 61 headings; depth classes for `#`/`##`/`###`; the first
entry marked at the start with the list at scrollTop 0; scrolling to
Section 16 marks it within 2 px of the list's center while the body's
scrollTop and `document.activeElement` stay unchanged; at the end the
list is at its own end; the third "Notes" entry lands the third Notes
heading at 8 px; choosing Section 30 near the end keeps it marked; the
button folds and restores the column.
- 390 phone: no column until the button; the drawer does not change the
body's width; opening centers and focuses Section 21; Escape closes only
the drawer and returns focus to the button; a choice scrolls to the
heading, closes, and returns focus; a tap on the document closes it.
- Narrow, after review: a dialog in front of the viewer (Settings) keeps
its Escape and focus while the drawer stays open; a touch stroke down
the drawer at its top does not drag the viewer's sheet.
- Docked at 1280: the toolbar's Outline button opens a drawer over the
panel, and the pane beside it keeps its Escape and focus.
- **Failing first:** with `src/` at origin/main the script fails at its
first step (no wrapper, no outline).
- `src/lib/markdownOutline.test.ts`: the entry list (levels, words with
formatting dropped, quoted headings left out, repeated titles as
separate places, wordless headings skipped) and the current-heading
rule.
- `src/lib/settings.test.ts`: the default, sanitising and device scope,
and the setting's own key surviving an old tab's whole-record save.

## Screenshots

Fixture data (no user session), 1280x800 and 390x844, dark and light;
checked by eye: the column and the drawer, the marked entry centered,
the indent per level, and the Outline button's on state.

## Validation

- `bun run check fast`: pass on the merged head 57863e2 (workflow
syntax, generated types/themes, typecheck, build, 12364 unit tests, 0
failures).
- `bun scripts/markdown-outline-browser-qa.ts`: pass, also on the merged
head (with `files-prompt-regression`, whose #3053 Escape steps landed
meanwhile).
- Sheet-drag regressions after the review fix (`src/lib/sheets.ts`), in
`herdr-ci-runner:local`: `key-bar-customization-demo-regression`,
`link-menu-demo-regression`, `phone-worktree-sheet-regression`: all
PASS.
- Browser regressions covering FileViewer, run in
`herdr-ci-runner:local`: all pass: `markdown-outline-browser-qa`,
`file-viewer-regression` (79 PASS), `file-viewer-mobile-regression`,
`file-preview-text-browser-qa`, `virtual-source-browser-qa`,
`files-panel-demo-regression`, `file-text-size-demo-regression`,
`settings-pages-demo-regression`, `deep-link-demo-regression`,
`render-crash-demo-regression`, `web-panel-mobile-regression`,
`repo-diff-browser-qa`, `relay-media-browser-qa`,
`link-menu-demo-regression`, and `files-prompt-regression` (through `bun
run check run`, 8 PASS).
- Not run: the full browser suite (CI runs it), and native iOS/Android
or Windows checks.
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.

Escape with two dialogs open can close the one underneath

1 participant