Repository navigation
fix(dialogs): Escape closes the dialog in front when two are open - #3053
Conversation
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
|
Warning Review limit reachedYou'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. View limit details
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. |
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).
|
Review summary for head 25fba2c:
|
|
Local merge gate (owner-approved): |
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.
Fixes #3037. Follow-up to #3036.
Problem
Settings, Files and New workspace each close on their own
windowordocumentEscape 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:documentlistener runs before Settings'windowlistener, 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)insrc/lib/useFocusTrap.ts: the focus is inside anotheraria-modalsurface. It is the checkFilesDialoghas done inline since fix(files): keep Escape closing Files when the key re-renders the app #3026; Files now calls the helper.SettingsDialogandNewSessionDialogleave 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
bun run check run --build bun scripts/files-prompt-regression.tswith 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 faston the rebased head: success (typecheck, build, 12289 unit tests, 0 failures).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-regressionandrevision-bound-update-demo-regressionpass on both (the first failures came from host load and a checkout whose git directory the container could not read).unconfirmed-input-demo-regressionfails 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.bun run check full, Windows VM, Mac.