Compare commits

..
Author SHA1 Message Date
Codeman maintainer 79f444a2fc fix(tabs): keep the working spinner on a ledger cell
The ledger layout hid every .tab-status to swap the dot for its coloured
bar. The bar is green for idle and working alike, and the spinner is the
dot's own .tab-status.busy::after ring, so a working session showed no
mark at all. A busy cell now keeps the dot and its ring, idle cells stay
bar-only, and an exited agent's cell still hides it like the classic strip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 09:46:23 +01:00
12 changed files with 40 additions and 760 deletions

No files matched your search

-5
View File
@@ -1,5 +0,0 @@
---
"aicodeman": patch
---
**Closing a dialog you opened with the mouse puts the keyboard back in the terminal.** After App Settings or Session Options was opened with a click and closed again, nothing you typed reached the terminal until you clicked it: focus was left on the button you had clicked, and in Safari and the Mac app on nothing at all. A dialog now returns the keyboard to the field you were typing in when you clicked, which with the tile grid or the split open is the pane you were in. The Session Manager and the command palette follow the same rule. A dialog opened with the keyboard still returns to the control it was opened from.
+5
View File
@@ -0,0 +1,5 @@
---
"aicodeman": patch
---
The Ledger tab layout shows the spinning ring on a working session again. The ledger swaps the status dot for a coloured bar, and that bar is green for idle and working alike, so hiding the dot also hid the only sign that a session was busy. A working cell now keeps the dot and its ring, the same mark the classic strip draws; idle cells stay bar-only, and an exited agent's cell still shows no ring.
-1
View File
@@ -28,7 +28,6 @@ export const BROWSER_TEST_GLOBS = [
'test/tab-layout-editing.browser.test.ts',
'test/tab-rail-search.browser.test.ts',
'test/tab-focus.browser.test.ts',
'test/dialog-focus-return.browser.test.ts',
'test/session-sidebar-ux.browser.test.ts',
'test/header-divider.browser.test.ts',
'test/tab-strip-corner.browser.test.ts',
+1 -1
View File
@@ -1211,7 +1211,7 @@ Tests: `test/terminal-touch-tap.test.ts`, `test/session-swipe-gesture.test.ts` (
⚠️ **The boxes ARE a DOM grouping**, unlike by state, which is safe only because a tab changes case far less often than it changes state: `_tabClusterLayout().key` is the whole structure, and the incremental path rebuilds whenever it differs from the last full render's. The keyboard walk keeps boxes together (box index first, then computed order, since a sorted rail orders rows inside each box). Drag only reorders inside one box, as it only reorders inside one state group (`_isTabDropAcrossGroups()`).
**Ledger.** CSS only, on `.tabs-ledger` inside `@media (min-width: 768px)` and the header host: the flat list on an auto-fill column grid with equal cells, mono type and a 3px status bar (`--ledger-bar`: yellow for a waiting alert, red for an action alert or an error, muted for stopped, exited and web tabs) instead of the dot. ⚠️ It must not change the markup (pinned: the ledger's innerHTML equals classic's); the rail, the sidebar and narrower strips show the plain list.
**Ledger.** CSS only, on `.tabs-ledger` inside `@media (min-width: 768px)` and the header host: the flat list on an auto-fill column grid with equal cells, mono type and a 3px status bar (`--ledger-bar`: yellow for a waiting alert, red for an action alert or an error, muted for stopped, exited and web tabs) instead of the dot. ⚠️ A WORKING cell keeps the dot (`.tab-status:not(.busy)` is what is hidden): the bar is green for idle and working alike, and the spinner is the dot's own `.tab-status.busy::after` ring, so hiding every dot left a busy session with no mark (pinned by `test/tab-clusters.test.ts`); an exited agent's cell hides it, as the classic strip hides the ring there. ⚠️ It must not change the markup (pinned: the ledger's innerHTML equals classic's); the rail, the sidebar and narrower strips show the plain list.
**Classic, wrapped: the L-shaped strip.** Once a classic desktop strip in the header host wraps (`tabs-auto-wrap`, or the manual `tabs-two-rows`), `_syncTabStripCorner()` (app.js) adds `.tabs-corner`: `#headerRight` goes `position: absolute` over the strip's top-right corner and the strip runs the header's full width, so only the row(s) beside the toolbar stop short of it and every later row uses the width under it. A flex line cannot be shortened on its own, so in that state the strip is `display: block` with `inline-flex` tabs flowing around a `::before` float sized from the toolbar's box (`--tab-corner-width` / `--tab-corner-height`); the old `row-gap` (lineage's `--lineage-row-gap` included) becomes the tabs' bottom margin and the bottom padding shrinks by the same amount, so row spacing and lineage routing room are unchanged. ⚠️ `updateTabOverflowMode()` removes `.tabs-corner` BEFORE it measures the wrap (the corner takes the toolbar out of the header's flow, which widens the strip), so the wrap is still judged against the one-row layout and an unwrapped strip looks exactly as before. ⚠️ Flex-only rules do not apply to the strip in that state. ⚠️ A strip that already scrolls (past `--tab-strip-max-height`) keeps the plain wrap, checked on the plain strip before the class goes on: the float scrolls with the tabs while the toolbar stays put, and toggling the class on a scrolled strip lets scroll anchoring move it; a strip pushed past the max-height by the float itself falls back too. A first tab too wide for the room beside the toolbar (the whole first line would drop below it) is trimmed to the room instead (`tab-corner-fit`, `max-width: var(--tab-corner-first-max)`, its name ellipsized): a selected tab is wider (gear and close show), so a fallback here made the whole layout follow the selection. Only a room under `TAB_CORNER_MIN_FIRST_TAB` keeps the plain wrap. ⚠️ The cap goes on the first tab on every pass, never only once it measures too wide: `selectSession()` widens a newly selected tab at once and this sync is debounced, so a cap set afterwards leaves the first row below the toolbar until it runs. It changes nothing on a tab narrower than the room. A `ResizeObserver` on the toolbar re-decides wrap and corner and redraws the connection lines when a reading or the header divider resizes it without a tab render. Scope: classic arrangement, desktop, header host only; state/case/ledger, the sidebar and the vertical rail never get the class (`applySessionListLayout()` drops it when the strip moves). Tests: `test/tab-strip-corner.browser.test.ts` (browser suite).
+1 -1
View File
@@ -43,7 +43,7 @@ per device, so a sidebar on your desktop does not force one onto your phone.
| ---------------------- | ------------------------------------------------------------------------------------ |
| **By state** | Groups the tabs by what each session needs from you (below). |
| **By case** | One box per case, labelled with the case and its tab count. Inside a box, `w75-api-gateway` reads just `w75`. A case with one tab gets a box with a colour swatch. |
| **Ledger** | The same list on an aligned column grid: equal cells, monospace names, a coloured bar on the left of each cell instead of the dot (yellow waiting, red needs you). Desktop header only. |
| **Ledger** | The same list on an aligned column grid: equal cells, monospace names, a coloured bar on the left of each cell instead of the dot (yellow waiting, red needs you); a working session keeps its spinning ring. Desktop header only. |
| **Classic** (default) | The single list in tab order, as before. |
**By state** groups the tabs like this, most urgent on top:
+1 -3
View File
@@ -38,7 +38,7 @@ Frontend JS modules have `@fileoverview` with `@dependency`/`@loadorder` tags. L
**Session list layout: header strip or left sidebar** (`sessionListLayout`, default `header`; per-device via `displayKeys`, also in `SettingsUpdateSchema`): the list can move into a collapsible `<aside>` (Alt+B, `toggleSessionSidebar`) or, via `tabOrientation`, a resizable vertical `#tabRail` (desktop/tablet only). ⚠️ There is ONE `#sessionTabs`, MOVED between hosts, never a second list: `applySessionListLayout()` runs first, then `applyTabOrientation()`, both BEFORE `applyTabWrapSettings()`, and both arm/disarm `_startSidebarRichClock()`. ⚠️ Axis decisions use `_isVerticalTabList()`, never `isSessionSidebarActive()` alone. ⚠️ Rich rows share one gate, `isRichTabRows()`; rich CSS pairs sidebar+rail with comma-grouped selectors, never `:is()`, and card rules stay rail-scoped. ⚠️ Rail sort (`tabRailSort`, default `activity`) is the flex `order` property only, never a DOM reorder; the arrow-key walk and the phone swipe follow computed `order`. ⚠️ Leaving sidebar mode clears `_sidebarFilter`; the handheld overlay drawer is `inert` when closed, the docked rail never. ⚠️ The rail's **Search sessions** box (`setTabRailSearch`, in memory only) and the sidebar filter share ONE row filter, `_applyTabListFilter()` over the pure `CodemanTabSearch` (constants.js): classes only, never a reorder or layout write; the rail matches the name, the sidebar name + folder. ⚠️ A session row with a tab alert (`tabAlerts`, red or yellow) is never hidden by either box: it goes in as `keep: true`, counts toward its group (which stays on screen) but not toward `matchCount`. ⚠️ Escape in the rail box is claimed by the global capture-phase Escape branch (the box's own `onkeydown` runs after it, too late to stop `closeAllPanels()`), and a filter change that shows or hides anything redraws the connector lines, since a keystroke re-renders nothing; a floating window finds its parent tab only through `_paintedSessionTab()` (a hidden row's rect is all zero but truthy, which drew connectors from the viewport's corner). While it runs `_projectTabGroups()` projects every group open (a collapsed group's rows are not in the DOM) and `toggleTabGroupCollapsed()` refuses, leaving the stored collapse untouched; drag stays on during a search (owner decision), a drop landing between the visible neighbours; `applyTabOrientation()` clears it off the rail. Tests: `test/tab-rail-search.test.ts`, `test/tab-rail-search.browser.test.ts`. → [architecture-invariants#session-list-layout-header-strip-vs-left-sidebar](../../docs/architecture-invariants.md#session-list-layout-header-strip-vs-left-sidebar)
**Tab layouts** (`tabArrangement`, per-device, default `classic`; `state`/`case`/`ledger` are opt-in; Discussion #426): `state` (option C) splits the list into needs you / waiting / working / idle (idle is `quiet`: its heading stays as the row's anchor but draws no label; `tabStateOrder: 'urgent-last'` flips the order, needs you at the bottom): rows in the desktop header strip with left-aligned labels in a measured column (the brand sits over the strip's corner, so the rows after the first start under "Codeman"), sections in the flat rail and the sidebar, inline dividers on the tablet strip, group order with no headings on phones. `case` (option A) wraps each case's tabs in one `.tab-cluster` box and hides the `-<case>` of a generated name (`.tab-name-case`). `ledger` (option B) is a CSS-only grid on the desktop header strip. `classic` is the old strip; once it wraps on desktop it is L-shaped via `_syncTabStripCorner()` (the toolbar sits over its top-right corner and later rows run the full width under it, a strip already past its max-height keeps the plain wrap): ⚠️ `.tabs-corner` comes off before the wrap is measured, and the strip is `display: block` in that state, so flex-only rules do not apply to it there (`test/tab-strip-corner.browser.test.ts`). Pure cores: `CodemanTabTriage` and `CodemanTabClusters` (constants.js). ⚠️ `state` is the flex `order` property plus `aria-hidden` heading/break elements reconciled in place by `_syncTabTriageChrome()` after BOTH render paths, never a DOM reorder (a state change is an incremental pass). ⚠️ `case` boxes ARE a DOM grouping, so the incremental path rebuilds whenever `_tabClusterLayout().key` changes; membership follows `_mobileOverviewCaseFor()` like the home screens. ⚠️ Drag only reorders within a group or box (`_isTabDropAcrossGroups()`). ⚠️ Named groups in the vertical rail win over both groupings. ⚠️ `classic` must leave no trace (no headings, no inline order, no boxes, no name split), and the ledger must not change the markup. ⚠️ Grouping is a render layer: `sessionOrder`, Alt+[ / Alt+], Ctrl+Tab and Alt+1..9 keep the canonical order, and only the phone swipe walks the drawn order (`nextSession({ visual: true })` through `_stripSessionOrder()`, the same `_visibleTabRows()` walk the strip's arrow keys use); an active session the list does not draw steps in at the first or last row, and an empty drawn list goes nowhere rather than falling back to a hidden session (`test/session-swipe-gesture.test.ts`). Tests: `test/tab-triage.test.ts`, `test/tab-clusters.test.ts`. → [architecture-invariants#tab-layouts-by-state-by-case-ledger](../../docs/architecture-invariants.md#tab-layouts-by-state-by-case-ledger)
**Tab layouts** (`tabArrangement`, per-device, default `classic`; `state`/`case`/`ledger` are opt-in; Discussion #426): `state` (option C) splits the list into needs you / waiting / working / idle (idle is `quiet`: its heading stays as the row's anchor but draws no label; `tabStateOrder: 'urgent-last'` flips the order, needs you at the bottom): rows in the desktop header strip with left-aligned labels in a measured column (the brand sits over the strip's corner, so the rows after the first start under "Codeman"), sections in the flat rail and the sidebar, inline dividers on the tablet strip, group order with no headings on phones. `case` (option A) wraps each case's tabs in one `.tab-cluster` box and hides the `-<case>` of a generated name (`.tab-name-case`). `ledger` (option B) is a CSS-only grid on the desktop header strip; its bar replaces the dot everywhere except a working cell, which keeps the dot and its spinning ring (the bar alone is green for idle and working alike). `classic` is the old strip; once it wraps on desktop it is L-shaped via `_syncTabStripCorner()` (the toolbar sits over its top-right corner and later rows run the full width under it, a strip already past its max-height keeps the plain wrap): ⚠️ `.tabs-corner` comes off before the wrap is measured, and the strip is `display: block` in that state, so flex-only rules do not apply to it there (`test/tab-strip-corner.browser.test.ts`). Pure cores: `CodemanTabTriage` and `CodemanTabClusters` (constants.js). ⚠️ `state` is the flex `order` property plus `aria-hidden` heading/break elements reconciled in place by `_syncTabTriageChrome()` after BOTH render paths, never a DOM reorder (a state change is an incremental pass). ⚠️ `case` boxes ARE a DOM grouping, so the incremental path rebuilds whenever `_tabClusterLayout().key` changes; membership follows `_mobileOverviewCaseFor()` like the home screens. ⚠️ Drag only reorders within a group or box (`_isTabDropAcrossGroups()`). ⚠️ Named groups in the vertical rail win over both groupings. ⚠️ `classic` must leave no trace (no headings, no inline order, no boxes, no name split), and the ledger must not change the markup. ⚠️ Grouping is a render layer: `sessionOrder`, Alt+[ / Alt+], Ctrl+Tab and Alt+1..9 keep the canonical order, and only the phone swipe walks the drawn order (`nextSession({ visual: true })` through `_stripSessionOrder()`, the same `_visibleTabRows()` walk the strip's arrow keys use); an active session the list does not draw steps in at the first or last row, and an empty drawn list goes nowhere rather than falling back to a hidden session (`test/session-swipe-gesture.test.ts`). Tests: `test/tab-triage.test.ts`, `test/tab-clusters.test.ts`. → [architecture-invariants#tab-layouts-by-state-by-case-ledger](../../docs/architecture-invariants.md#tab-layouts-by-state-by-case-ledger)
**Header stats styles** (`headerStatsStyle`, per-device, desktop only, default `compact`; Discussion #426 option G): `tiles` / `compact` (two pills, a ring beside every value) / `classic` (as before), keyed on `data-header-stats` (pre-paint + `applyHeaderStatsStyle()`), forced to `classic` below 768px and in a solo window. ⚠️ The clustered styles MOVE `#connectionIndicator` into `#headerSystemStats` and `#planUsageChip` right after it; `classic` moves them back to comment anchors. ⚠️ WS joins the pill only while System Stats is shown. ⚠️ The extra parts (stat rings, tile words, plan rings, meters) are always rendered and hidden by default in CSS, which is what keeps `classic` unchanged; tile words are derived beside the connection descriptor, never added to it (`test/connection-indicator.test.ts` pins its shape). ⚠️ A tile is a three-row grid (label, value, bar) with pixel line-heights and the bundled JetBrains Mono; never lay the bar over a fixed-height tile (a taller system mono put the value on top of it). The WS tile's grid lives on the inner `.connection-tile`, because JS writes the indicator's `display` inline. Tests: `test/header-stats-style.test.ts`. → [architecture-invariants#header-stats-styles](../../docs/architecture-invariants.md#header-stats-styles)
@@ -56,8 +56,6 @@ Frontend JS modules have `@fileoverview` with `@dependency`/`@loadorder` tags. L
**Command palette + shortcut registry**: `Ctrl/Cmd/Alt+K` opens the session palette; shortcuts live in a rebindable registry (`DEFAULT_SHORTCUTS`/`getShortcutRegistry()`/`matchesShortcutEvent()` in app.js, overrides in `settings.shortcutOverrides`). ⚠️ Palette-chord keys must ALSO be swallowed in `attachCustomKeyEventHandler` (terminal-ui.js) or xterm writes the control byte into the PTY. ⚠️ The global Escape handler (app.js) calls EVERY close method on every Escape, in the capture phase, so a close method that does more than hide (the palette and Session Manager restore focus) must return early when its overlay is not open. ⚠️ `saveAppSettings()` rebuilds settings from the DOM, so keys edited elsewhere (`shortcutOverrides`, `showTokenCount`, `showCost`) need explicit `_prev` carry-over. ⚠️ **Smart copy (`Ctrl+C`)**: with no selection it must `return true` without `preventDefault()` or the interrupt is lost; keep `copyTerminalSelection` out of `SHORTCUT_ACTIONS`. The gate tests the CLEANED selection (`CodemanCopySelection.clean`: trailing padding, plus a LEADING margin only up to the width the CLI declares in `capabilities.transcriptGutter`, never one derived from the pane); the strip is not idempotent, so clean once and pass the RAW selection on, and leave Alt+drag column selections untouched. → [architecture-invariants#command-palette-and-shortcut-registry](../../docs/architecture-invariants.md#command-palette-and-shortcut-registry)
**Where a dialog hands the keyboard back to** (`FocusTrap.focusToReturn()`, keyboard-accessory.js): a dialog that saves focus on open asks this, never `document.activeElement`. By the time a dialog opens, the mouse press that opened it has already moved focus (onto the pressed control in Chromium and Firefox, onto `<body>` in WebKit on macOS, where a button takes no focus from the mouse), and restoring that left the keyboard out of the terminal until it was clicked. The answer is the typing field (textarea, text-like input, editable region) that had focus at `pointerdown`, whenever focus now sits on the pressed control or on `<body>`. ⚠️ `pointerdown`, never `mousedown` or `click`: moving focus is `mousedown`'s default action, so only the earlier event still sees what had the keyboard. ⚠️ One press, from a typing field, by mouse: the field of an earlier press is not carried over (it can be behind a dialog opened since), a press that began on a button (a dialog opened inside a dialog) still returns to the pressed control, any key but a held modifier forgets the press (a keyboard user gets the control back), and a finger or pen records nothing (a focused field there means the on-screen keyboard). The one press that inherits a field is a press on an item inside `[role="menu"]`, from the press that opened the menu (a tile's menu button, then "Session options"); a menu that hands focus back to its trigger before running the item is not covered. ⚠️ Asking spends the press, so nothing pressed inside the opening dialog can hand the keyboard to a field behind it; call it once, when the dialog opens. Callers: `FocusTrap.activate()` (App Settings, Session Options, Help, Kill All, the phone composer) and `_rememberOverlayFocus()` (command palette, Session Manager); the local model window places its own focus. A dialog that never handed focus back (most of the small confirm dialogs) is not changed by this. Tests: `test/dialog-focus-return.test.ts`, `test/dialog-focus-return.browser.test.ts` (real Chromium, not in the gate).
**Per-device vs synced settings**: the `displayKeys` set in settings-ui.js is a **client-side merge policy**, not a wire filter. A display key seeds from the server only when localStorage has no value for it, which is what prevents one device overwriting another; `showPlanUsageLimits` is additionally `delete`d from the incoming payload outright. Separately, `SettingsUpdateSchema` is `.strict()` and simply **does not declare** `skin`, `showFileViewerButton`, `showCronButton`, `webglRendererEnabled`, `localEchoEnabled`, `keyboardHoldsRows`, `cjkInputEnabled`, `cjkInputHoldUntilEnter`, or `extendedKeyboardBar`, so sending one of those is a validation error. The rest (`showResponseViewer`, `showPlanUsageLimits`, `language`, and most `show*` keys) ARE in the schema and do persist server-side; they are per-device by client policy only. ⚠️ Adding a new per-device setting means deciding **both** questions: membership in `displayKeys`, and presence in the schema.
**Settings surface** (`#appSettingsModal` + `#sessionOptionsModal` + `#createCaseModal`): one `set-*` language shared through a single `:is(...)` id scope in styles.css. App Settings' rail is a table of contents over ONE scrolling document (`switchSettingsTab` scrolls); Session Options and Add Case really switch (`switchOptionsTab` / `switchCaseModalTab`), and their larger per-modal size blocks are the design, not drift. ⚠️ **The load/save contract is `getElementById` by id**: renaming or dropping a control id silently stops it loading or saving. ⚠️ The Session Options "Session" entry still keys off `context` (label-only rename). ⚠️ Add Case keeps its legacy `.form-row` markup via an adapter; every `<details>` there needs `.set-adv-chev` plus both marker suppressions. ⚠️ Model cards and the effort segment are views over hidden `<select>`s, which stay the source of truth. ⚠️ `.modal-tabs*` classes are retired; `admin-ui.js` needs `.set-rail-items` + `.set-doc` to survive any restructure. Guard: `test/app-settings-structure.test.ts`. → [architecture-invariants#settings-surface-app-settings-session-options-add-case](../../docs/architecture-invariants.md#settings-surface-app-settings-session-options-add-case)
+1 -106
View File
@@ -27,8 +27,6 @@
*
* - FocusTrap (class) — Traps Tab/Shift+Tab keyboard focus within a modal element.
* Saves and restores previously focused element on deactivate. Used by the modal dialogs.
* A dialog opened by a mouse press goes back to the field the user was typing in when
* the press began (FocusTrap.focusToReturn), not to the pressed control.
*
* @globals {object} KeyboardAccessoryBar
* @globals {object} PathPicker
@@ -1848,13 +1846,6 @@ const KeyboardAccessoryBar = {
/**
* FocusTrap - Traps keyboard focus within an element (typically a modal).
* Saves the previously focused element and restores focus when deactivated.
*
* What it saves is {@link FocusTrap.focusToReturn}, not `document.activeElement`.
* By the time a dialog opens, the mouse press that opened it has already moved
* focus: in Chromium and Firefox the pressed control took it, and in WebKit on
* macOS (Safari, the Mac app) a button takes no focus from the mouse, so the
* press clears focus to `<body>`. Handing either one back left the keyboard out
* of the terminal the user was typing in until they clicked it again.
*/
class FocusTrap {
constructor(element) {
@@ -1863,96 +1854,8 @@ class FocusTrap {
this.boundHandleKeydown = this.handleKeydown.bind(this);
}
/**
* The element a dialog that is about to open should hand the keyboard back to
* when it closes.
*
* That is `document.activeElement`, with one exception: a dialog opened by a
* mouse press while the user was typing in a field (a terminal's textarea, the
* CJK field, a search box). The field is the answer when that press is the
* only reason focus is somewhere else now, which is the case when focus sits
* on the pressed control or on nothing at all.
*
* ⚠️ One press, and only from a typing field. A press made from a button (a
* dialog opened from inside another dialog) still returns to the pressed
* control, and the field of an earlier press is not carried over: it can be
* behind a dialog that has opened since. The one exception is a press on a
* menu item, see {@link FocusTrap._notePress}. A control reached with the
* keyboard keeps the usual pattern too, because any key forgets the press.
*
* ⚠️ Asking spends the press. Whatever is pressed inside the dialog that is
* opening starts with nothing remembered, so nothing in it can hand the
* keyboard to a field behind it.
*/
static focusToReturn() {
const active = document.activeElement || null;
const press = FocusTrap._press;
FocusTrap._press = null;
if (!press || !press.field || press.field === active || press.field.isConnected === false) return active;
const moved =
!active ||
active === document.body ||
active === press.target ||
(typeof active.contains === 'function' && active.contains(press.target));
return moved ? press.field : active;
}
/** True for an element text is typed into: a textarea, a text-like input, an editable region. */
static isTypingField(el) {
if (!el || el === document.body) return false;
const tag = String(el.tagName || '').toUpperCase();
if (tag === 'TEXTAREA') return true;
if (tag === 'INPUT') return !FocusTrap.NON_TEXT_INPUT_TYPES.includes(String(el.type || 'text').toLowerCase());
return el.isContentEditable === true;
}
/**
* Remember what a mouse press began on and which typing field had the keyboard.
*
* ⚠️ `pointerdown`, not `mousedown` or `click`: moving focus is the default
* action of `mousedown`, which comes after it, so `activeElement` is still the
* element that had the keyboard before the press.
*
* ⚠️ A finger or a pen forgets the press and records nothing: on a touch device
* a focused field means the on-screen keyboard, and handing focus back to it
* would raise the keyboard when a dialog closes.
*
* ⚠️ A press on an item of a menu (`[role="menu"]`) keeps the field of the
* press before it, the one that opened the menu: a tile's menu button and then
* "Session options" are two presses and one way into a dialog. No other press
* inherits a field.
*/
static _notePress(e) {
if (!e || e.pointerType !== 'mouse') {
FocusTrap._press = null;
return;
}
const active = document.activeElement;
const target = e.target || null;
let field = FocusTrap.isTypingField(active) ? active : null;
if (!field && FocusTrap._press && typeof target?.closest === 'function' && target.closest('[role="menu"]')) {
field = FocusTrap._press.field;
}
FocusTrap._press = { target, field };
}
/** Any key but a modifier held for the click (Shift+click) ends the press's say. */
static _forgetPress(e) {
if (e && FocusTrap.MODIFIER_KEYS.includes(e.key)) return;
FocusTrap._press = null;
}
/** Install the two document listeners behind {@link FocusTrap.focusToReturn}, once per page. */
static watchPresses() {
if (FocusTrap._watching) return;
if (typeof document === 'undefined' || typeof document.addEventListener !== 'function') return;
FocusTrap._watching = true;
document.addEventListener('pointerdown', FocusTrap._notePress, true);
document.addEventListener('keydown', FocusTrap._forgetPress, true);
}
activate() {
this.previouslyFocused = FocusTrap.focusToReturn();
this.previouslyFocused = document.activeElement;
this.element.addEventListener('keydown', this.boundHandleKeydown);
// Focus first focusable element after a brief delay (for CSS transitions)
@@ -2004,11 +1907,3 @@ class FocusTrap {
}
}
}
/** The last mouse press, `{ target, field }`, or null. See {@link FocusTrap._notePress}. */
FocusTrap._press = null;
FocusTrap._watching = false;
/** `<input>` types nobody types text into; every other type counts as a typing field. */
FocusTrap.NON_TEXT_INPUT_TYPES = ['button', 'checkbox', 'color', 'file', 'hidden', 'image', 'radio', 'range', 'reset', 'submit'];
FocusTrap.MODIFIER_KEYS = ['Shift', 'Control', 'Alt', 'Meta'];
FocusTrap.watchPresses();
+1 -8
View File
@@ -376,14 +376,7 @@ Object.assign(CodemanApp.prototype, {
* for, typing a filter the moment it opens.
*/
_rememberOverlayFocus(key) {
if (typeof document === 'undefined') {
this[key] = null;
return;
}
// The same answer a FocusTrap dialog saves (keyboard-accessory.js): an overlay
// opened by a mouse press goes back to the field the user was typing in, not
// to the pressed button.
this[key] = (typeof FocusTrap === 'function' ? FocusTrap.focusToReturn() : document.activeElement) || null;
this[key] = (typeof document !== 'undefined' && document.activeElement) || null;
},
/**
+7 -1
View File
@@ -23615,7 +23615,13 @@ html[data-session-list='sidebar'][data-sidebar='collapsed'] .session-sidebar .ta
font-weight: 500;
}
.session-tabs-host > .session-tabs.tabs-ledger > .session-tab .tab-status {
/* The bar replaces the dot, except on a WORKING cell: the bar is green for
idle and working alike, so the dot and its orbiting ring
(.tab-status.busy::after) stay, the same "working" mark the classic strip
and the home screens draw. An exited agent's cell hides it anyway, as the
classic strip hides the ring there. */
.session-tabs-host > .session-tabs.tabs-ledger > .session-tab .tab-status:not(.busy),
.session-tabs-host > .session-tabs.tabs-ledger > .session-tab.tab-agent-exited .tab-status {
display: none;
}
-274
View File
@@ -1,274 +0,0 @@
/**
* @fileoverview Real-Chromium coverage for where a dialog hands the keyboard
* back to (`FocusTrap.focusToReturn`, keyboard-accessory.js).
*
* What the vm test in `test/dialog-focus-return.test.ts` cannot answer is the
* order a browser does things in: the rule reads `document.activeElement` in a
* `pointerdown` listener and relies on the engine moving focus only afterwards,
* as the default action of `mousedown`. Here a real mouse presses real controls
* and a real keyboard types, on a page that holds the shipping
* keyboard-accessory.js, a textarea standing in for the terminal's own, and a
* dialog built on `FocusTrap` the way App Settings and Session Options are.
*
* Four ways into the dialog: a button (Chromium gives it focus on a press), an
* element that cannot take focus (the press clears focus to `<body>`, which is
* what WebKit on macOS does for a button), a focusable element pressed on an
* icon inside it (a tab's gear), and an item of a menu opened by a press before
* it (a tile's menu button, then "Session options").
*
* Port: none (page.route on a fake origin, no server).
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
import { chromium, type Browser, type BrowserContext, type Page } from 'playwright';
const publicDir = resolve(import.meta.dirname, '../src/web/public');
const ORIGIN = 'http://codeman.test/';
const PAGE = `<!doctype html><html><body>
<textarea id="term" style="display:block;width:300px;height:80px"></textarea>
<button id="other">Other</button>
<button id="open">Open</button>
<div id="plain" style="display:inline-block;padding:8px;background:#ccc">Open, takes no focus</div>
<span id="gear" tabindex="0" style="display:inline-block;padding:8px">
<svg width="24" height="24"><rect id="gearIcon" width="24" height="24"></rect></svg>
</span>
<button id="menuButton">Menu</button>
<div id="modal" hidden style="position:fixed;left:40px;top:160px;padding:20px;background:#eee">
<button id="close">Close</button><input id="name">
</div>
</body></html>`;
const WIRING = `
const modal = document.getElementById('modal');
const focused = () => (document.activeElement === document.body ? 'body' : document.activeElement.id);
window.__focused = focused;
window.__focusAtClick = [];
let trap = null;
const open = () => {
window.__focusAtClick.push(focused());
modal.hidden = false;
trap = new FocusTrap(modal);
trap.activate();
};
const close = () => {
if (!trap) return;
modal.hidden = true;
trap.deactivate();
trap = null;
};
for (const id of ['open', 'plain', 'gear']) document.getElementById(id).addEventListener('click', open);
document.getElementById('close').addEventListener('click', close);
// A menu the way the rail's row menu is built: appended to <body>, its first
// item focused, removed by the item's click before the action runs.
document.getElementById('menuButton').addEventListener('click', () => {
const menu = document.createElement('div');
menu.id = 'menu';
menu.setAttribute('role', 'menu');
menu.style.cssText = 'position:fixed;left:400px;top:160px;padding:8px;background:#ddd';
for (const [id, action] of [['menuFirst', () => {}], ['menuOptions', open]]) {
const item = document.createElement('button');
item.id = id;
item.setAttribute('role', 'menuitem');
item.textContent = id;
item.addEventListener('click', () => {
menu.remove();
action();
});
menu.appendChild(item);
}
document.body.appendChild(menu);
menu.querySelector('button').focus();
});
document.addEventListener('keydown', (e) => { if (e.key === 'Escape') close(); }, true);
`;
describe('where a dialog hands the keyboard back to, in Chromium', () => {
let browser: Browser;
const contexts: BrowserContext[] = [];
let page: Page;
const errors: string[] = [];
async function newPage(options: { hasTouch?: boolean } = {}): Promise<Page> {
const context = await browser.newContext({ viewport: { width: 800, height: 500 }, ...options });
contexts.push(context);
const p = await context.newPage();
p.on('pageerror', (e) => errors.push(e.message));
await p.route(ORIGIN, (route) => route.fulfill({ contentType: 'text/html', body: PAGE }));
await p.goto(ORIGIN);
await p.addScriptTag({ content: readFileSync(resolve(publicDir, 'keyboard-accessory.js'), 'utf8') });
await p.addScriptTag({ content: WIRING });
return p;
}
const focused = (p: Page = page) => p.evaluate(() => (window as any).__focused());
const focusAtClick = (p: Page = page) => p.evaluate(() => (window as any).__focusAtClick);
const termText = (p: Page = page) => p.evaluate(() => (document.getElementById('term') as HTMLTextAreaElement).value);
/** Put the keyboard in the terminal stand-in and type, as a user in the middle of a prompt. */
async function typeInTerminal(p: Page = page) {
await p.click('#term');
await p.keyboard.type('a');
expect(await focused(p)).toBe('term');
}
/** The trap moves focus to the dialog's first control one frame after it opens. */
async function dialogOpen(p: Page = page) {
await p.waitForFunction(() => (window as any).__focused() === 'close');
}
beforeAll(async () => {
browser = await chromium.launch({ headless: true });
});
beforeEach(async () => {
errors.length = 0;
page = await newPage();
});
afterAll(async () => {
for (const context of contexts) await context.close();
await browser?.close();
});
it('a button pressed with the mouse: the keyboard is back in the terminal', async () => {
await typeInTerminal();
await page.click('#open');
await dialogOpen();
// The engine fact the rule exists for: the press gave the button focus.
expect(await focusAtClick()).toEqual(['open']);
await page.keyboard.press('Escape');
expect(await focused()).toBe('term');
await page.keyboard.type('b');
expect(await termText()).toBe('ab');
expect(errors).toEqual([]);
});
it('a control that takes no focus (a button in WebKit on macOS): the keyboard is back in the terminal', async () => {
await typeInTerminal();
await page.click('#plain');
await dialogOpen();
// The press cleared focus: before the fix this is what the dialog handed back.
expect(await focusAtClick()).toEqual(['body']);
await page.keyboard.press('Escape');
expect(await focused()).toBe('term');
await page.keyboard.type('b');
expect(await termText()).toBe('ab');
});
it("a press on the icon inside a focusable control (a tab's gear): the keyboard is back in the terminal", async () => {
await typeInTerminal();
await page.click('#gearIcon');
await dialogOpen();
expect(await focusAtClick()).toEqual(['gear']);
await page.keyboard.press('Escape');
expect(await focused()).toBe('term');
await page.keyboard.type('b');
expect(await termText()).toBe('ab');
});
it("two presses through a menu (a tile's menu, then Session options): the keyboard is back in the terminal", async () => {
await typeInTerminal();
await page.click('#menuButton');
expect(await focused()).toBe('menuFirst');
await page.click('#menuOptions');
await dialogOpen();
// The item's click removed the menu, so nothing had focus when the dialog opened.
expect(await focusAtClick()).toEqual(['body']);
await page.keyboard.press('Escape');
expect(await focused()).toBe('term');
await page.keyboard.type('b');
expect(await termText()).toBe('ab');
});
it('a menu walked with the keyboard keeps the keyboard pattern', async () => {
await typeInTerminal();
await page.click('#menuButton');
await page.keyboard.press('Tab');
expect(await focused()).toBe('menuOptions');
await page.keyboard.press('Enter');
await dialogOpen();
await page.keyboard.press('Escape');
// Nothing was remembered: the dialog hands back what had focus, and that was nothing.
expect(await focused()).not.toBe('term');
});
it('closing the dialog with the mouse instead of Escape changes nothing', async () => {
await typeInTerminal();
await page.click('#open');
await dialogOpen();
await page.click('#close');
expect(await focused()).toBe('term');
await page.keyboard.type('b');
expect(await termText()).toBe('ab');
});
it('typing in the dialog and opening it a second time still ends in the terminal', async () => {
await typeInTerminal();
await page.click('#open');
await dialogOpen();
await page.click('#name');
await page.keyboard.type('x');
await page.keyboard.press('Escape');
expect(await focused()).toBe('term');
await page.click('#open');
await dialogOpen();
await page.keyboard.press('Escape');
expect(await focused()).toBe('term');
await page.keyboard.type('b');
expect(await termText()).toBe('ab');
});
it('a keyboard user gets the control back that opened the dialog', async () => {
await typeInTerminal();
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
expect(await focused()).toBe('open');
await page.keyboard.press('Enter');
await dialogOpen();
await page.keyboard.press('Escape');
expect(await focused()).toBe('open');
});
it('a keyboard user gets the control back even after pressing it with the mouse earlier', async () => {
await typeInTerminal();
await page.click('#open');
await dialogOpen();
await page.keyboard.press('Escape');
expect(await focused()).toBe('term');
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await page.keyboard.press('Enter');
await dialogOpen();
await page.keyboard.press('Escape');
expect(await focused()).toBe('open');
});
it('a press that began on a button returns to the pressed control, as before', async () => {
await typeInTerminal();
await page.click('#other');
expect(await focused()).toBe('other');
await page.click('#open');
await dialogOpen();
await page.keyboard.press('Escape');
expect(await focused()).toBe('open');
});
it('a finger changes nothing: focus returns to what had it when the dialog opened', async () => {
const touch = await newPage({ hasTouch: true });
await touch.tap('#term');
expect(await focused(touch)).toBe('term');
await touch.tap('#open');
await dialogOpen(touch);
const atClick = (await focusAtClick(touch))[0];
await touch.keyboard.press('Escape');
expect(await focused(touch)).toBe(atClick);
});
});
-360
View File
@@ -1,360 +0,0 @@
/**
* @fileoverview A dialog hands the keyboard back to the field the user was
* typing in when the mouse press that opened it began.
*
* Measured in Chromium against a real shell session before the change: App
* Settings opened from the header gear and closed left `activeElement` on the
* gear button, Session Options opened from a tab's gear left it on that gear,
* and nothing typed afterwards reached the terminal. With the press clearing
* focus (what WebKit on macOS does for a button) it was left on `<body>`.
*
* `FocusTrap` is loaded with `vm` against a fake document, like the other
* accessory-bar tests. A press is the two steps a browser takes: `pointerdown`
* reaches the page first, then the engine moves focus. The real event order is
* covered in `test/dialog-focus-return.browser.test.ts`.
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import vm from 'node:vm';
import { describe, expect, it, vi } from 'vitest';
type Listener = (e: unknown) => void;
type Node = Record<string, any>;
const read = (name: string) => readFileSync(resolve(import.meta.dirname, '../src/web/public', name), 'utf8');
function node(tagName: string, extra: Node = {}): Node {
return { tagName, isConnected: true, focus: vi.fn(), contains: () => false, ...extra };
}
function loadPage({ panels = false } = {}) {
const listeners: Record<string, Listener[]> = {};
const body = node('BODY');
let active: Node | null = body;
const document = {
body,
get activeElement() {
return active;
},
addEventListener: (type: string, fn: Listener, capture?: boolean) => {
(listeners[`${type}:${capture === true}`] ||= []).push(fn);
},
createElement: () => node('DIV'),
querySelector: () => null,
getElementById: () => null,
};
const CodemanApp = function CodemanApp(this: unknown) {};
const context = vm.createContext({
console,
document,
CodemanApp,
MobileDetection: { isTouchDevice: () => false },
localStorage: { getItem: () => null, setItem: () => {} },
requestAnimationFrame: (fn: () => void) => fn(),
});
vm.runInContext(`${read('keyboard-accessory.js')}\nglobalThis.__FocusTrap = FocusTrap;`, context, {
filename: 'keyboard-accessory.js',
});
if (panels) vm.runInContext(read('panels-ui.js'), context, { filename: 'panels-ui.js' });
const FocusTrap = (context as unknown as { __FocusTrap: any }).__FocusTrap;
const fire = (type: string, event: unknown) => (listeners[`${type}:true`] ?? []).forEach((fn) => fn(event));
return {
FocusTrap,
listeners,
body,
app: panels ? new (CodemanApp as any)() : null,
setActive: (el: Node | null) => (active = el),
/** A press: the page hears `pointerdown`, then the engine moves focus to `focusAfter`. */
press(target: Node, focusAfter?: Node | null, pointerType = 'mouse') {
fire('pointerdown', { pointerType, target });
if (focusAfter !== undefined) active = focusAfter;
},
key: (key: string) => fire('keydown', { key }),
};
}
describe('FocusTrap.focusToReturn', () => {
it('answers the typing field when the pressed control took focus (Chromium, Firefox)', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear);
expect(page.FocusTrap.focusToReturn()).toBe(terminal);
});
it('answers the typing field when the press cleared focus (a button in WebKit on macOS)', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
page.setActive(terminal);
page.press(node('BUTTON'), page.body);
expect(page.FocusTrap.focusToReturn()).toBe(terminal);
});
it('answers the typing field when the press landed inside the control that took focus', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const icon = node('path');
const gear = node('BUTTON', { contains: (el: Node) => el === icon });
page.setActive(terminal);
page.press(icon, gear);
expect(page.FocusTrap.focusToReturn()).toBe(terminal);
});
it('keeps the control for a keyboard user: any key forgets the press', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear);
// Later the same control is reached with Tab and opened with Enter.
page.key('Tab');
expect(page.FocusTrap.focusToReturn()).toBe(gear);
});
it('does not let a modifier held for the click forget the press', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear);
for (const key of ['Shift', 'Control', 'Alt', 'Meta']) page.key(key);
expect(page.FocusTrap.focusToReturn()).toBe(terminal);
});
it('returns to the pressed control when the press came from a button (a dialog opened inside a dialog)', () => {
const page = loadPage();
const closeButton = node('BUTTON');
const row = node('BUTTON');
page.setActive(closeButton);
page.press(row, row);
expect(page.FocusTrap.focusToReturn()).toBe(row);
});
it('never carries the field of an earlier press over', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
const row = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear);
// A dialog is open now and the terminal is behind it; the next press starts from a button.
page.press(row, row);
expect(page.FocusTrap.focusToReturn()).toBe(row);
});
it('keeps the field through a menu: the press on a menu item belongs to the press that opened the menu', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const menuButton = node('BUTTON');
const firstItem = node('BUTTON');
const item = node('BUTTON', { closest: (selector: string) => (selector === '[role="menu"]' ? {} : null) });
page.setActive(terminal);
// The menu focuses its first item when it opens.
page.press(menuButton, firstItem);
// The item's click removes the menu, which drops focus on <body>, and opens the dialog.
page.press(item, page.body);
expect(page.FocusTrap.focusToReturn()).toBe(terminal);
});
it('keeps nothing through a menu that was opened from a button', () => {
const page = loadPage();
const closeButton = node('BUTTON');
const menuButton = node('BUTTON');
const item = node('BUTTON', { closest: (selector: string) => (selector === '[role="menu"]' ? {} : null) });
page.setActive(closeButton);
page.press(menuButton, menuButton);
page.press(item, page.body);
expect(page.FocusTrap.focusToReturn()).toBe(page.body);
});
it('spends the press when a dialog asks, so nothing pressed inside the dialog reaches the field behind it', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear);
expect(page.FocusTrap.focusToReturn()).toBe(terminal);
expect(page.FocusTrap.focusToReturn()).toBe(gear);
// The dialog is open. A menu item in it is pressed directly, with a dialog control focused.
const dialogControl = node('BUTTON');
const item = node('BUTTON', { closest: (selector: string) => (selector === '[role="menu"]' ? {} : null) });
page.setActive(dialogControl);
page.press(item, page.body);
expect(page.FocusTrap.focusToReturn()).toBe(page.body);
});
it('leaves a finger alone, and a finger forgets an earlier mouse press', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear, 'touch');
expect(page.FocusTrap.focusToReturn()).toBe(gear);
page.setActive(terminal);
page.press(gear, gear, 'mouse');
page.press(gear, gear, 'touch');
expect(page.FocusTrap.focusToReturn()).toBe(gear);
page.setActive(terminal);
page.press(gear, gear, 'pen');
expect(page.FocusTrap.focusToReturn()).toBe(gear);
});
it('answers what has focus when the field is gone from the page', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear);
terminal.isConnected = false;
expect(page.FocusTrap.focusToReturn()).toBe(gear);
});
it('answers what has focus when the click itself moved it somewhere else', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const elsewhere = node('BUTTON');
page.setActive(terminal);
page.press(node('BUTTON'), elsewhere);
expect(page.FocusTrap.focusToReturn()).toBe(elsewhere);
});
it('answers what has focus when there was no press at all', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
page.setActive(terminal);
expect(page.FocusTrap.focusToReturn()).toBe(terminal);
page.setActive(page.body);
expect(page.FocusTrap.focusToReturn()).toBe(page.body);
});
it('answers the field itself when the press left focus in it', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
page.setActive(terminal);
// An accessory key cancels the mousedown default, so the terminal keeps focus.
page.press(node('BUTTON'));
expect(page.FocusTrap.focusToReturn()).toBe(terminal);
});
});
describe('FocusTrap.isTypingField', () => {
it('counts textareas, text-like inputs and editable regions, and nothing else', () => {
const { FocusTrap, body } = loadPage();
expect(FocusTrap.isTypingField(node('TEXTAREA'))).toBe(true);
expect(FocusTrap.isTypingField(node('textarea'))).toBe(true);
expect(FocusTrap.isTypingField(node('INPUT'))).toBe(true);
for (const type of ['text', 'search', 'number', 'password', 'email', 'url']) {
expect(FocusTrap.isTypingField(node('INPUT', { type }))).toBe(true);
}
for (const type of [
'button',
'checkbox',
'color',
'file',
'hidden',
'image',
'radio',
'range',
'reset',
'submit',
]) {
expect(FocusTrap.isTypingField(node('INPUT', { type }))).toBe(false);
}
expect(FocusTrap.isTypingField(node('DIV', { isContentEditable: true }))).toBe(true);
expect(FocusTrap.isTypingField(node('DIV'))).toBe(false);
expect(FocusTrap.isTypingField(node('BUTTON'))).toBe(false);
expect(FocusTrap.isTypingField(node('SELECT'))).toBe(false);
expect(FocusTrap.isTypingField(body)).toBe(false);
expect(FocusTrap.isTypingField(null)).toBe(false);
});
});
describe('the document listeners', () => {
it('are two capture listeners, installed once however often the page asks', () => {
const page = loadPage();
page.FocusTrap.watchPresses();
page.FocusTrap.watchPresses();
expect(Object.keys(page.listeners).sort()).toEqual(['keydown:true', 'pointerdown:true']);
expect(page.listeners['pointerdown:true']).toHaveLength(1);
expect(page.listeners['keydown:true']).toHaveLength(1);
});
it('are skipped on a page with no document to listen on', () => {
const context = vm.createContext({ console, document: { createElement: () => node('DIV') } });
vm.runInContext(`${read('keyboard-accessory.js')}\nglobalThis.__FocusTrap = FocusTrap;`, context);
expect((context as unknown as { __FocusTrap: any }).__FocusTrap._watching).toBe(false);
});
});
describe('a dialog built on FocusTrap', () => {
function dialog() {
return { addEventListener: vi.fn(), removeEventListener: vi.fn(), querySelectorAll: () => [] };
}
it('hands the keyboard back to the terminal after it was opened by a mouse press', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear);
const trap = new page.FocusTrap(dialog());
trap.activate();
expect(trap.previouslyFocused).toBe(terminal);
trap.deactivate();
expect(terminal.focus).toHaveBeenCalledTimes(1);
expect(gear.focus).not.toHaveBeenCalled();
});
it('still hands it back to the control it was opened from with the keyboard', () => {
const page = loadPage();
const gear = node('BUTTON');
page.setActive(gear);
page.key('Enter');
const trap = new page.FocusTrap(dialog());
trap.activate();
trap.deactivate();
expect(gear.focus).toHaveBeenCalledTimes(1);
});
it('is not misled by the press that closes it', () => {
const page = loadPage();
const terminal = node('TEXTAREA');
const gear = node('BUTTON');
const close = node('BUTTON');
page.setActive(terminal);
page.press(gear, gear);
const trap = new page.FocusTrap(dialog());
trap.activate();
page.setActive(close);
page.press(close, close);
trap.deactivate();
expect(terminal.focus).toHaveBeenCalledTimes(1);
});
});
describe('the command palette and the Session Manager', () => {
it('save the same answer, so an overlay opened by a mouse press returns to the terminal', () => {
const page = loadPage({ panels: true });
const terminal = node('TEXTAREA');
const headerButton = node('BUTTON');
page.setActive(terminal);
page.press(headerButton, headerButton);
page.app._rememberOverlayFocus('_sessionManagerPrevFocus');
expect(page.app._sessionManagerPrevFocus).toBe(terminal);
});
it('save what has focus when the overlay was opened with its shortcut', () => {
const page = loadPage({ panels: true });
const terminal = node('TEXTAREA');
page.setActive(terminal);
page.key('k');
page.app._rememberOverlayFocus('_commandPalettePrevFocus');
expect(page.app._commandPalettePrevFocus).toBe(terminal);
});
});
+23
View File
@@ -345,6 +345,29 @@ describe('tab layouts by case and ledger (static)', () => {
);
});
it('keeps the working spinner on a ledger cell', () => {
// The bar replaces the status dot, but it is green for idle and working
// alike, and the spinner is the dot's own ::after ring: hiding every dot
// left a working session with no mark at all.
const hides: string[] = [];
postcss.parse(css).walkAtRules('media', (media: AtRule) => {
if (media.params !== '(min-width: 768px)') return;
media.walkRules((rule: Rule) => {
if (!rule.selector.includes('.tabs-ledger')) return;
if (!rule.nodes.some((n) => n.type === 'decl' && n.prop === 'display' && n.value === 'none')) return;
hides.push(...rule.selectors.filter((s) => s.includes('.tab-status')));
});
});
expect(hides.length).toBeGreaterThan(0);
for (const selector of hides) {
// Each one either spares a busy dot or is the exited-agent cell, whose
// ring the classic strip hides too.
expect(selector.endsWith('.tab-status:not(.busy)') || selector.includes('.tab-agent-exited')).toBe(true);
}
// The ring the cell keeps is the shared one every strip draws.
expect(css).toMatch(/\.session-tab \.tab-status\.busy::after \{[^}]*animation: tab-load-spin/);
});
it('dissolves the boxes into the one chip row on phones', () => {
expect(mobileCss).toMatch(
/:where\(\.header\) \.session-tabs-host > \.session-tabs\.tabs-clusters > \.tab-cluster \{\s*display: contents;/