Skip to content

Commit 4455ac0

Browse files
authored
Complete the visual review keyboard journey (#624)
Visual-review evidence can overflow inside its own stage, but the shared reading keys previously selected the outer pane, and changing cases or refreshing the source could leave keyboard focus on the document body. This makes every visual case a nested reading region and preserves the active inspection or disposition destination through case selection and source updates. Nested regions distinguish the semantic host used by reading commands from the body that actually contains a control. Response placement, thread-preview placement, and reading-position continuity now share the same outward containment walk as scroller selection, so case conversation stays visible through bounded/flow changes without treating the capture stage as its boundary. Reading keys still use the semantic host, preserving pane ownership from frame controls. Moving an outdated draft from an inline case outlet back to the floating response surface also preserves its exact focused control and text selection without reclaiming focus if the reader moved elsewhere. The end-to-end journey now uses rendered Go-to and target-chooser hints to inspect evidence, page through an overflowing capture, review cases, preserve an exact case comment and draft across a 390px covering Threads view and desktop nonmodal Threads, update source data while that draft is open, apply corrected evidence, and record the final disposition. It uses Leaf's canonical focus-ring reading and asserts exact source provenance and that local inspection creates no durable actions. The broader two-pane landmark and focus-paint audit remains tracked in the workspace follow-up for TODO #14. Tests: `uv run pytest tests/test_render_visual_review_journey.py -q -n0 -x`; `uv run pytest tests/test_render_navigation.py -q -n0 -x`; `uv run pytest tests/test_render_conversations.py -q -n0 -x`; `uv run pytest tests/test_render_projection.py::test_a_source_replacement_preserves_the_focused_draft_and_its_original_anchor -q -n0 -x`; `bin/leaf package check skills/leaf/packages/visual-review`; `uv run pre-commit run --all-files`. The full two-worker suite previously reached 1,037/1,038; its sole runtime-banner startup timeout reproduced on the frozen merge base under the same platform, selection, and parallelism. > _This was written by Codex on behalf of max-sixty_
1 parent 602c6b6 commit 4455ac0

9 files changed

Lines changed: 408 additions & 46 deletions

File tree

‎notes/workspace-followups.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ Items are ranked within each group. IDs are stable references, not a global prio
200200

201201
- **#14** **Verify the complete keyboard and accessibility route** — Exercise the workspace as one keyboard task, including reading, pane furniture, local comments and Threads.
202202

203-
**Evidence / confidence:** Composition verification task. The suite has reading-region keyboard tests and menu/accessibility coverage. Those components do not by themselves prove the composed split-plus-Threads journey, especially when content is covered.
203+
**Evidence / confidence:** Composition verification task. The visual-review journey now covers real Go-to controls and pane furniture, case-local comments, covering and nonmodal Threads, draft restoration, bounded/flow transitions, and shared reading keys. A general named two-pane journey still needs to walk authored landmarks plus header and footer controls together and verify every painted focus mark remains unobscured.
204204

205-
**Next task:** Use a named two-pane example with header/footer controls; walk landmarks and controls, use reading keys, open Threads, return through Escape, then change posture. Check focus against actual modal/nonmodal behavior.
205+
**Next task:** Use a named two-pane example with header/footer controls; walk authored landmarks and controls, use reading keys, open Threads, return through Escape, then change posture. Check focus against actual modal/nonmodal behavior.
206206

207207
**Done when:** Every action is reachable with a comprehensible accessible name and visible focus. Covered content does not leave the reader lost. Avoid imposing a modal focus trap on a nonmodal panel.
208208

‎skills/leaf/assets/runtime/composing/surface.js‎

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import { anchorLabel } from "../conversation/messages.js";
8585
import { reactionsAt } from "../conversation/model.js";
8686
import { allThreads } from "../conversation/state.js";
8787

88-
import { readingRegionFor, shownRegionBounds } from "../reading-regions.js";
88+
import { containingReadingRegionFor, shownRegionBounds } from "../reading-regions.js";
8989

9090
export const BANNER_CLEAR = 48;
9191
let floatingUiModule = null;
@@ -246,26 +246,39 @@ export function createResponseSurface({
246246
? Promise.resolve(true)
247247
: new Promise((resolve) => fabPositionWaiters.push(resolve));
248248

249+
const captureFabFocus = () => {
250+
const element = focused();
251+
if (!(element instanceof HTMLElement) || !fabBar.contains(element)) return null;
252+
const selection =
253+
element === fabInput
254+
? {
255+
start: element.selectionStart,
256+
end: element.selectionEnd,
257+
direction: element.selectionDirection,
258+
}
259+
: null;
260+
return { element, selection };
261+
};
262+
263+
const restoreFabFocus = (held) => {
264+
if (!held || focused() === held.element || !held.element.isConnected) return;
265+
held.element.focus({ preventScroll: true });
266+
if (held.selection)
267+
held.element.setSelectionRange(
268+
held.selection.start,
269+
held.selection.end,
270+
held.selection.direction,
271+
);
272+
};
273+
249274
// Reparenting the canonical response bar is presentation, not a composer transition.
250275
// Preserve the exact typing position across light/shadow DOM moves; Chromium may put
251276
// focus on the shadow host while a focused textarea is adopted into its tree.
252277
function moveFab(parent) {
253278
if (fabBar.parentElement === parent) return;
254-
const held = focused();
255-
const holdsFocus = held instanceof HTMLElement && fabBar.contains(held);
256-
const selection =
257-
holdsFocus && held === fabInput
258-
? {
259-
start: held.selectionStart,
260-
end: held.selectionEnd,
261-
direction: held.selectionDirection,
262-
}
263-
: null;
279+
const held = captureFabFocus();
264280
parent.append(fabBar);
265-
if (!holdsFocus || focused() === held) return;
266-
held.focus({ preventScroll: true });
267-
if (selection)
268-
held.setSelectionRange(selection.start, selection.end, selection.direction);
281+
restoreFabFocus(held);
269282
}
270283

271284
function seatFab(outlet) {
@@ -285,12 +298,23 @@ export function createResponseSurface({
285298

286299
function restoreFab({ place = true } = {}) {
287300
if (!fabInlineOutlet && fabBar.parentElement === responseHome) return false;
301+
// Resetting the inline presentation hides the response before moving it back to the
302+
// viewport plane. Capture the exact focused control first; hiding a focused subtree
303+
// makes Chromium move focus to body before moveFab can observe what was held.
304+
const held = captureFabFocus();
288305
stopFabPositioning({ reset: true });
289306
fabInlineOutlet = null;
290307
fabFloating = true;
291308
delete fabBar.dataset.lfPresentation;
292309
moveFab(responseHome);
293-
if (place && fabAnchor && !placeFab()) showFab(null);
310+
if (place && fabAnchor) {
311+
const displacedFocus = focused();
312+
if (!placeFab()) showFab(null);
313+
else if (held)
314+
void fabPositioned().then((positioned) => {
315+
if (positioned && focused() === displacedFocus) restoreFabFocus(held);
316+
});
317+
}
294318
return true;
295319
}
296320

@@ -382,7 +406,7 @@ export function createResponseSurface({
382406
if (!fabAnchor || !target) return false;
383407
const owner = fabTargetAt();
384408
const block = fabAnchor.quote && owner;
385-
const readingRegion = owner && readingRegionFor(owner);
409+
const readingRegion = owner && containingReadingRegionFor(owner);
386410
let regionBounds = readingRegion && shownRegionBounds(readingRegion);
387411
let boundary = floatBoundary(regionBounds);
388412
// Keep the response within its pane while that pane can hold the compact control.

‎skills/leaf/assets/runtime/margin-projection.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ import { clampedRow, PRESS } from "./keyboard/bindings.js";
7575
import { beginWalk, listWalkPosition } from "./walk-position.js";
7676
import { ago, clocked } from "./presence.js";
7777
import { runtime } from "./context.js";
78-
import { readingRegionFor, shownRegionBounds } from "./reading-regions.js";
78+
import {
79+
containingReadingRegionFor,
80+
readingRegionFor,
81+
shownRegionBounds,
82+
} from "./reading-regions.js";
7983
import { panelWouldCover } from "./conversation/panel-elements.js";
8084
import { COVERING } from "./chrome-layout.js";
8185

@@ -821,7 +825,7 @@ export function createMarginProjection({
821825
const controls =
822826
previewMarginEntry.closest("[data-lf-margin-for]") ?? previewMarginEntry;
823827
const target = controls.getBoundingClientRect();
824-
const readingRegion = readingRegionFor(previewEntry?.target);
828+
const readingRegion = containingReadingRegionFor(previewEntry?.target);
825829
const regionBounds = readingRegion && shownRegionBounds(readingRegion);
826830
const main = readingRegion
827831
? null

‎skills/leaf/assets/runtime/reading-regions.js‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ export const readingRegionFor = (node) => {
124124
return region && regionRecord(region);
125125
};
126126

127+
// The deepest region whose body actually contains this node. A region's host includes
128+
// its frame furniture so focus there can still select the region for reading commands;
129+
// geometry that must contain the node itself instead walks outward to the body it lives
130+
// in. Keep that containment walk shared with scrollerFor so placement and travel cannot
131+
// disagree about which reading box holds a control.
132+
export const containingReadingRegionFor = (node) => {
133+
let region = readingRegionFor(node);
134+
while (region) {
135+
if (containsAcross(region.body, node)) return region;
136+
region = readingRegionFor(region.host.parentElement);
137+
}
138+
return undefined;
139+
};
140+
127141
const asRegion = (regionOrNode) =>
128142
typeof regionOrNode === "string"
129143
? regions.get(regionOrNode)
@@ -154,12 +168,8 @@ export function effectiveScroller(regionOrNode) {
154168
// by nothing else. A drag naming the wrong one sits at the edge waiting for a scroll
155169
// that never comes.
156170
export const scrollerFor = (el) => {
157-
let region = readingRegionFor(el);
158-
while (region) {
159-
if (containsAcross(region.body, el)) return effectiveScroller(region);
160-
region = readingRegionFor(region.host.parentElement);
161-
}
162-
return pageScroller;
171+
const region = containingReadingRegionFor(el);
172+
return region ? effectiveScroller(region) : pageScroller;
163173
};
164174

165175
export function shownRegionBounds(regionOrNode) {

‎skills/leaf/assets/runtime/version.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ import { registry, stateSpecs, tagsDeclaring } from "./registry.js";
131131
import { targetElement, targetSegments } from "./resolved-target.js";
132132
import { moveScrollerBy, pageScroller } from "./scrolling.js";
133133
import {
134+
containingReadingRegionFor,
134135
effectiveScroller,
135136
readingPosture,
136137
readingRegionFor,
@@ -1567,7 +1568,8 @@ export function createVersionController({
15671568
function restoreView(view) {
15681569
setLanded((view.ask && document.getElementById(view.ask)) || null);
15691570
const regions = new Map(readingRegions().map((region) => [region.id, region]));
1570-
const active = readingRegionFor(focused()) ?? readingRegionFor(readingBlock());
1571+
const active =
1572+
containingReadingRegionFor(focused()) ?? readingRegionFor(readingBlock());
15711573
const restored = new Set();
15721574
if (active && view.regions?.[active.id]) {
15731575
restoreRegion(view.regions[active.id], regions.get(active.id));
@@ -1594,8 +1596,13 @@ export function createVersionController({
15941596
let navigationIntent = 0;
15951597
let lastReadingRegionId = null;
15961598

1599+
// Continuity restores scroll geometry, not the reading-key subject. Frame furniture
1600+
// still names its own pane to d/u through readingRegionFor; because the furniture does
1601+
// not live in that pane's scroller, a posture change preserves the outer region that
1602+
// geometrically contains it. The same distinction keeps an inline response outside a
1603+
// nested region body with the outer scroller that actually carries it.
15971604
const activeReadingRegion = (candidates = readingRegions()) => {
1598-
const focusedRegion = readingRegionFor(focused());
1605+
const focusedRegion = containingReadingRegionFor(focused());
15991606
if (focusedRegion && candidates.some(({ id }) => id === focusedRegion.id))
16001607
return focusedRegion;
16011608
const recent = candidates.find(({ id }) => id === lastReadingRegionId);

‎skills/leaf/packages/visual-review/theme.css‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ lf-visual-review > .lf-reading-after {
116116
min-width: 0;
117117
}
118118

119+
.lf-vr-toolbar-slot {
120+
padding-block: var(--here-ring-w);
121+
}
122+
119123
.lf-vr-inspector[hidden] {
120124
display: none;
121125
}
@@ -311,7 +315,9 @@ lf-visual-review > .lf-reading-after {
311315
}
312316

313317
.lf-vr-details[open] {
318+
display: grid;
314319
grid-column: 1 / -1;
320+
gap: var(--sp-2);
315321
width: auto;
316322
}
317323

@@ -327,7 +333,7 @@ lf-visual-review > .lf-reading-after {
327333
display: grid;
328334
grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
329335
gap: var(--sp-2) var(--sp-4);
330-
margin: var(--sp-2) 0 0;
336+
margin: 0;
331337
padding: var(--sp-2);
332338
border: 1px solid var(--rule);
333339
border-radius: var(--r);

‎skills/leaf/packages/visual-review/widgets/lf-visual-review.js‎

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
PRESS,
2020
projectData,
2121
registerReadingElement,
22+
registerReadingRegion,
2223
registerThreadSurface,
2324
relabel,
2425
scopedMediaUrl,
@@ -129,6 +130,7 @@ customElements.define(
129130
readingArrangement: this.#arrangements.at(-1),
130131
minimumSize: () => ({ width: 720, height: 600 }),
131132
});
133+
for (const [id, entry] of this.#caseEntries) this.#registerCaseRegion(id, entry);
132134
this.#sizes = new ResizeObserver(() => this.#scheduleEvidenceLayout());
133135
this.#sizes.observe(this);
134136
for (const stage of this.querySelectorAll(".lf-vr-shot-host"))
@@ -151,6 +153,10 @@ customElements.define(
151153
this.stopWatching = null;
152154
this.#threadSurface?.unregister();
153155
this.#threadSurface = null;
156+
for (const entry of this.#caseEntries.values()) {
157+
entry.stopReading?.();
158+
entry.stopReading = null;
159+
}
154160
this.#fitting?.cleanup();
155161
this.#fitting = null;
156162
this.#sizes?.disconnect();
@@ -638,8 +644,10 @@ customElements.define(
638644
this.#inspector.hidden = true;
639645
this.#evidenceHost.append(this.#inspector);
640646
this.#queue.replaceChildren();
641-
for (const { shotHost } of this.#caseEntries.values())
647+
for (const { shotHost, stopReading } of this.#caseEntries.values()) {
642648
this.#sizes?.unobserve(shotHost);
649+
stopReading?.();
650+
}
643651
this.#caseEntries.clear();
644652
this.#selected = null;
645653
this.#paintNavigation();
@@ -666,6 +674,7 @@ customElements.define(
666674
for (const [id, entry] of this.#caseEntries) {
667675
if (wanted.has(id)) continue;
668676
this.#sizes?.unobserve(entry.shotHost);
677+
entry.stopReading?.();
669678
entry.option.remove();
670679
entry.article.remove();
671680
this.#caseEntries.delete(id);
@@ -787,11 +796,37 @@ customElements.define(
787796
threadOutlet.dataset.lfGen = "1";
788797
threadOutlet.setAttribute("aria-label", "Threads on this visual case");
789798
article.append(heading, claim, toolbar, shotHost, support, threadOutlet);
790-
return { article, option, shotHost, record: null, index: 0, total: 0 };
799+
const entry = {
800+
article,
801+
option,
802+
shotHost,
803+
stopReading: null,
804+
record: null,
805+
index: 0,
806+
total: 0,
807+
};
808+
this.#registerCaseRegion(id, entry);
809+
return entry;
810+
}
811+
812+
#registerCaseRegion(id, entry) {
813+
if (entry.stopReading) return;
814+
// The case's prose and controls are its furniture; the aligned captures are what
815+
// the reader pages through. Making that relationship a nested reading region lets
816+
// the shared d/u and j/k routes follow the selected case without a package key.
817+
entry.stopReading = registerReadingRegion({
818+
id: compoundReadingRegionId(this, `case-${id}`),
819+
host: entry.article,
820+
body: entry.shotHost,
821+
});
791822
}
792823

793824
#updateCase(entry, record, index, total) {
794825
entry.article.dataset.classification = record.classification;
826+
entry.article.setAttribute(
827+
"aria-label",
828+
`Visual review case ${index + 1} of ${total}`,
829+
);
795830
entry.record = record;
796831
entry.index = index;
797832
entry.total = total;
@@ -886,6 +921,12 @@ customElements.define(
886921

887922
#select(id) {
888923
if (!this.#caseEntries.has(id)) return;
924+
const currentEntry = this.#caseEntries.get(this.#selected);
925+
const active = document.activeElement;
926+
const leavingCase = Boolean(active && currentEntry?.article.contains(active));
927+
const disposition = leavingCase
928+
? active.closest(".lf-vr-disposition")?.dataset.disposition
929+
: null;
889930
if (id !== this.#selected) this.#scope = "focus";
890931
this.#selected = id;
891932
for (const [caseId, entry] of this.#caseEntries) {
@@ -894,12 +935,31 @@ customElements.define(
894935
entry.option.selected = selected;
895936
}
896937
const selected = this.#caseEntries.get(id);
897-
selected.article.querySelector(".lf-vr-toolbar-slot").append(this.#inspector);
938+
const toolbar = selected.article.querySelector(".lf-vr-toolbar-slot");
939+
if (this.#inspector.parentElement !== toolbar) toolbar.append(this.#inspector);
898940
this.#paintInspector();
899941
this.#threadSurface?.update();
900942
layoutChanged(this);
901943
this.#scheduleEvidenceLayout();
902944
paintKeys();
945+
// Moving the shared inspector between articles makes the browser drop its focus.
946+
// Restore that exact destination; a hidden case-local control instead lands on
947+
// the corresponding disposition — or the primary disposition when it has no
948+
// counterpart — rather than leaving a keyboard reader on the document body.
949+
if (
950+
leavingCase &&
951+
(document.activeElement !== active ||
952+
!active.isConnected ||
953+
!active.checkVisibility())
954+
) {
955+
const counterpart =
956+
active.isConnected && active.checkVisibility()
957+
? active
958+
: disposition
959+
? selected.article.querySelector(`[data-disposition="${disposition}"]`)
960+
: selected.article.querySelector(".lf-vr-disposition");
961+
counterpart?.focus({ preventScroll: true });
962+
}
903963
}
904964

905965
#step(delta) {

0 commit comments

Comments
 (0)