Skip to content

Commit ed6508b

Browse files
authored
Unify inline page-map threads (#172)
Inline page-map threads carried a redundant local route back to Threads, routed `c` away from the visible conversation, and changed posture while the page was still moving. This makes the inline conversation the direct reply surface, removes the redundant local route, and places thread cards beside their Button after any panel motion settles. The newer target-Button model now handles non-thread readings directly, so asks and outcomes no longer open a second, differently placed preview. Browser coverage checks the first painted frame, panel-to-inline transitions, keyboard reply focus, multi-thread cards, and the exact Button/card boundary. > _This was written by Codex on behalf of @max-sixty_
1 parent 027bdb1 commit ed6508b

10 files changed

Lines changed: 164 additions & 96 deletions

File tree

‎examples/corpus.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ <h2>Readiness docket</h2>
12971297
<strong>Ship offline editing in the first patch</strong> The beta is green
12981298
except for the reconnect exception below.
12991299
<lf-task id="off-t-resync" status="stalled" owner="mobile">
1300-
<strong>iOS resync stall</strong> One reconnect in about 40. Nothing is
1300+
<strong>iOS reconnect stall</strong> One reconnect in about 40. Nothing is
13011301
lost — the edits stay queued — but the reader sees a spinner until they
13021302
background the app.
13031303
</lf-task>

‎examples/ship-review.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ <h2>Readiness docket</h2>
4444
<strong>Ship offline editing in the first patch</strong> The beta is green
4545
except for the reconnect exception below.
4646
<lf-task id="off-t-resync" status="stalled" owner="mobile">
47-
<strong>iOS resync stall</strong> One reconnect in about 40. Nothing is
47+
<strong>iOS reconnect stall</strong> One reconnect in about 40. Nothing is
4848
lost — the edits stay queued — but the reader sees a spinner until they
4949
background the app.
5050
</lf-task>

‎scripts/record-demo.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,7 @@ def shot(duration: int) -> None:
285285
page.locator(".lf-composer").get_by_role("button", name="Comment").click()
286286
page.wait_for_selector(".lf-margin-thread")
287287
shot(1500)
288-
page.locator(".lf-margin-preview").get_by_role(
289-
"button", name="Open this thread in Threads"
290-
).click()
288+
page.locator(".lf-threads-toggle").click()
291289
page.wait_for_selector(".lf-thread")
292290

293291
comment_id = wait_for_comment(page_dir)

‎skills/leaf/CLAUDE.md‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,15 @@ performing it. In the compact posture, an informational item opens the Page map
13891389
at that location instead of reviving the hidden desktop preview; an action-only item
13901390
keeps its direct focus arrival on the action docked into the page.
13911391

1392+
A thread card names the target without offering a second route to the panel the banner
1393+
already opens. At wide widths it is the conversation itself, measured eight pixels
1394+
beside the pressed Thread Button in the same turn it is shown or changes size. While
1395+
that Button keeps focus, `c` enters the card's one reply box; several roots leave the
1396+
destination ambiguous and preserve the page's ordinary route to the panel. Replacing an
1397+
open panel waits for the body's strip motion before choosing the card posture. When the
1398+
document cannot leave the card room beside its Button, the press opens the full Threads
1399+
surface instead.
1400+
13921401
`margin-layout` places, packs, docks, and measures the complete host. Its rail
13931402
claim is the widest stable contribution seen and is monotonic for the document's
13941403
lifetime, so settling an action cannot shift the readable column. A temporary
@@ -1757,8 +1766,9 @@ reader stands in one place at a time, so it is several rows spelling one key,
17571766
each live exactly where the others are not.
17581767

17591768
Its destination is the anchor the 💬 carries, then the open thread the reader is
1760-
in, then the item they are standing in, and, when none of those is in hand, the
1761-
conversation itself. `commentDestination` decides it once and states the
1769+
in or the single inline thread held by a pressed Page-map marker, then the item they are
1770+
standing in, and, when none of those is in hand, the conversation itself.
1771+
`commentDestination` decides it once and states the
17621772
sentence, the key line and the press together, so the reference, the line and
17631773
what happens cannot come to spell it differently. The pointer's answers outrank
17641774
the standing: a selection or a raised 💬 is the more recent thing the reader

‎skills/leaf/assets/leaf.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ import { createBannerShelf } from "./runtime/banner-shelf.js";
255255
import { createConversationBox } from "./runtime/conversation/box.js";
256256
import {
257257
backFromConversation,
258+
conversationInput,
258259
createConversationLanding,
259260
heldConversation,
260261
landIn,
@@ -1574,7 +1575,10 @@ const commentDestination = () => {
15741575
),
15751576
go: () => fab.click(),
15761577
};
1577-
const said = standingConversation();
1578+
const inline = livingMargin?.activeInlineThread();
1579+
const inlineBox = inline && conversationInput(inline);
1580+
const said =
1581+
standingConversation() ?? (inlineBox ? { held: inline, box: inlineBox } : null);
15781582
if (said) return { ...commenting("thread"), go: () => landIn(said) };
15791583
const here = standingItem();
15801584
if (here) return { ...commenting(itemWord(here)), go: () => commentOnItem(here) };

‎skills/leaf/assets/runtime/chrome-style.js‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,28 +1202,23 @@ ${MARK_RULES}
12021202
--lf-here-ring: help-command; outline-offset: 1px; }
12031203
.lf-help-command[data-lf-available="false"] { color: var(--muted); }
12041204
.lf-page-map-toggle { display: none; }
1205-
.lf-margin-preview { position: fixed; position-anchor: --lf-margin-preview;
1206-
position-area: inline-start center; position-try-fallbacks: flip-inline, flip-block;
1205+
.lf-margin-preview { position: fixed;
12071206
z-index: 9150; width: min(320px, calc(100vw - 24px));
12081207
max-height: calc(100vh - 24px); box-sizing: border-box; overflow: auto;
12091208
scroll-padding-block: var(--here-ring-room);
12101209
margin: 0 8px; padding: 12px; border: 1px solid var(--border-2); border-radius: 10px;
12111210
background: var(--paper); color: var(--ink); box-shadow: 0 12px 36px rgba(0,0,0,.18); }
1212-
/* A compact preview follows its marker through native anchor positioning. The full
1213-
conversation instead has its fixed top measured from that marker: the card also
1211+
/* The conversation has its fixed position measured from its Button: the card also
12141212
changes the document's container posture, and asking both layout systems to
12151213
resolve that boundary can leave the browser oscillating between the two. */
12161214
.lf-margin-preview[data-lf-thread] { position-anchor: auto; position-area: none;
12171215
position-try-fallbacks: none;
1218-
inset: var(--lf-thread-top, calc(var(--lf-banner-h) + 8px)) 8px auto auto;
1219-
width: min(var(--thread-card), calc(100vw - 24px));
1216+
inset: var(--lf-thread-top, calc(var(--lf-banner-h) + 8px)) auto auto
1217+
var(--lf-thread-left, 8px);
1218+
width: min(var(--thread-card), calc(100vw - var(--lf-thread-left, 8px) - 8px));
12201219
max-height: calc(100vh - var(--lf-banner-h) - 16px); margin: 0; }
12211220
.lf-margin-preview-head, .lf-page-map-head { display: flex; align-items: center;
12221221
gap: 8px; }
1223-
.lf-margin-thread-action { flex: none; margin: 0; padding: 2px 7px;
1224-
border-color: var(--rule); background: transparent; color: var(--muted);
1225-
font-size: var(--t-6); }
1226-
.lf-margin-thread-action[hidden] { display: none; }
12271222
.lf-margin-preview-title { flex: 1; min-width: 0; font-size: var(--t-5);
12281223
line-height: 1.35; }
12291224
.lf-margin-preview-close { flex: none; min-width: 30px; padding-inline: 7px; }

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

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,11 @@ export function createLivingMargin(dependencies) {
268268
preview.setAttribute("popover", "auto");
269269
preview.setAttribute("role", "dialog");
270270
const previewHead = el("div", "lf-margin-preview-head");
271-
const previewThreadAction = el("button", "lf-btn lf-margin-thread-action", "Threads");
272-
previewThreadAction.type = "button";
273271
const previewTitle = el("strong", "lf-margin-preview-title");
274272
const previewClose = el("button", "lf-btn lf-margin-preview-close", "×");
275273
previewClose.type = "button";
276274
previewClose.setAttribute("aria-label", "Close thread");
277-
previewHead.append(previewThreadAction, previewTitle, previewClose);
275+
previewHead.append(previewTitle, previewClose);
278276
const previewList = el("div", "lf-margin-preview-list");
279277
preview.append(previewHead, previewList);
280278
chromeRoot.append(preview);
@@ -312,6 +310,7 @@ export function createLivingMargin(dependencies) {
312310
let highlighted = null;
313311
let rovingFrame = 0;
314312
let sheetActivation = false;
313+
let previewRequest = 0;
315314
// The cascade owns available room: panels and trays change the body's named
316315
// container, while an authored sidebar claims the page's left strip. Read the
317316
// posture it resolved instead of asking the viewport a different question.
@@ -451,27 +450,32 @@ export function createLivingMargin(dependencies) {
451450
render();
452451
});
453452
}
453+
function placeThreadPreview() {
454+
if (
455+
!preview.matches(":popover-open") ||
456+
!preview.hasAttribute("data-lf-thread") ||
457+
!previewButton?.isConnected
458+
)
459+
return;
460+
const marker = previewButton.getBoundingClientRect();
461+
const besideLeft = Math.max(8, marker.right + 8);
462+
preview.style.setProperty("--lf-thread-left", `${besideLeft}px`);
463+
const card = preview.getBoundingClientRect();
464+
const bannerBottom =
465+
document.querySelector(".lf-banner")?.getBoundingClientRect().bottom ?? 0;
466+
const firstTop = bannerBottom + 8;
467+
const lastTop = innerHeight - card.height - 8;
468+
const besideTop = (marker.top + marker.bottom - card.height) / 2;
469+
preview.style.setProperty(
470+
"--lf-thread-top",
471+
`${Math.max(firstTop, Math.min(besideTop, lastTop))}px`,
472+
);
473+
}
454474
function scheduleThreadPreviewPosition() {
455475
if (previewPositionFrame) return;
456476
previewPositionFrame = requestAnimationFrame(() => {
457477
previewPositionFrame = 0;
458-
if (
459-
!preview.matches(":popover-open") ||
460-
!preview.hasAttribute("data-lf-thread") ||
461-
!previewButton?.isConnected
462-
)
463-
return;
464-
const marker = previewButton.getBoundingClientRect();
465-
const cardHeight = preview.getBoundingClientRect().height;
466-
const bannerBottom =
467-
document.querySelector(".lf-banner")?.getBoundingClientRect().bottom ?? 0;
468-
const firstTop = bannerBottom + 8;
469-
const lastTop = innerHeight - cardHeight - 8;
470-
const besideTop = (marker.top + marker.bottom - cardHeight) / 2;
471-
preview.style.setProperty(
472-
"--lf-thread-top",
473-
`${Math.max(firstTop, Math.min(besideTop, lastTop))}px`,
474-
);
478+
placeThreadPreview();
475479
});
476480
}
477481
// A viewport posture change can replace the focused full conversation with its
@@ -1362,17 +1366,8 @@ export function createLivingMargin(dependencies) {
13621366
const targetHeading = entry.target?.querySelector(":scope > strong")?.textContent;
13631367
const title = trimmed(targetHeading || entry.title, 72);
13641368
preview.setAttribute("data-lf-thread", "");
1365-
scheduleThreadPreviewPosition();
13661369
preview.setAttribute("aria-label", `Thread for ${title}`);
13671370
previewTitle.textContent = title;
1368-
previewThreadAction.hidden = false;
1369-
previewThreadAction.setAttribute(
1370-
"aria-label",
1371-
threadItems.length === 1
1372-
? "Open this thread in Threads"
1373-
: "Open threads for this passage",
1374-
);
1375-
previewThreadAction.onclick = () => openThreads(threadItems, entry);
13761371
const nodes = threadItems.map(previewItemNode);
13771372
const keep = new Set(nodes);
13781373
for (const child of [...previewList.children]) if (!keep.has(child)) child.remove();
@@ -1392,6 +1387,7 @@ export function createLivingMargin(dependencies) {
13921387
previewClose);
13931388
destination.focus({ preventScroll: true });
13941389
}
1390+
placeThreadPreview();
13951391
}
13961392

13971393
function previewItemNode(item) {
@@ -1451,7 +1447,7 @@ export function createLivingMargin(dependencies) {
14511447
previewShowing = false;
14521448
}
14531449
}
1454-
scheduleThreadPreviewPosition();
1450+
placeThreadPreview();
14551451
highlight(entry.target);
14561452
for (const row of rows.values())
14571453
syncThreadRelation(row, markerNeedsPreview(row.lfEntry));
@@ -1504,17 +1500,29 @@ export function createLivingMargin(dependencies) {
15041500
}
15051501

15061502
function openThreadChoice(entry, button) {
1507-
if (panelIsOpen()) setPanel(false);
1508-
if (expandedOptionsKey && expandedOptionsKey !== entry.key)
1509-
setOptionsOpen(entry, false);
1510-
const choice = threadReading(entry);
1511-
if (!choice) return;
1512-
if (!threadBeside()) {
1513-
setOptionsOpen(entry, false);
1514-
openThreads(choice.items, entry);
1503+
const open = () => {
1504+
if (expandedOptionsKey && expandedOptionsKey !== entry.key)
1505+
setOptionsOpen(entry, false);
1506+
const choice = threadReading(entry);
1507+
if (!choice) return;
1508+
if (!threadBeside()) {
1509+
setOptionsOpen(entry, false);
1510+
openThreads(choice.items, entry);
1511+
return;
1512+
}
1513+
togglePinned(entry, button);
1514+
};
1515+
if (panelIsOpen()) {
1516+
const request = ++previewRequest;
1517+
setPanel(false);
1518+
const movements = document.body.getAnimations();
1519+
Promise.allSettled(movements.map((movement) => movement.finished)).then(() => {
1520+
if (request === previewRequest && button.isConnected) open();
1521+
});
15151522
return;
15161523
}
1517-
togglePinned(entry, button);
1524+
previewRequest += 1;
1525+
open();
15181526
}
15191527

15201528
function openThreads(threadItems, entry) {
@@ -1658,10 +1666,27 @@ export function createLivingMargin(dependencies) {
16581666
},
16591667
{ capture: true, passive: true },
16601668
);
1661-
window.addEventListener("resize", schedulePostureRender);
1669+
window.addEventListener("resize", () => {
1670+
placeThreadPreview();
1671+
schedulePostureRender();
1672+
});
16621673
render();
16631674

16641675
return {
1676+
activeInlineThread: () => {
1677+
if (
1678+
!pinnedKey ||
1679+
previewEntry?.key !== pinnedKey ||
1680+
document.activeElement !== previewButton ||
1681+
!preview.matches(":popover-open") ||
1682+
!preview.hasAttribute("data-lf-thread")
1683+
)
1684+
return null;
1685+
const conversations = previewList.querySelectorAll(
1686+
".lf-margin-thread .lf-conversation-thread",
1687+
);
1688+
return conversations.length === 1 ? conversations[0] : null;
1689+
},
16651690
closePreview: () => closePreview(false),
16661691
enterPageMap,
16671692
marginTargetAt,

‎tests/test_render_drafts.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ def test_a_held_comment_send_leaves_a_later_reply_box_focused(browser, serve):
837837

838838
def test_a_comment_hidden_by_narrowing_opens_its_inline_reply(browser, serve):
839839
"""A sent comment preserves the panel's narrowing while its inline conversation
840-
takes the reader; explicitly opening that thread then widens the panel."""
840+
takes the reader; reopening the overview keeps that filter intact."""
841841
page, errors = open_page(browser, serve(NOTED_PAGE, comments=1))
842842
page.locator(".lf-threads-toggle").click()
843843
panel_settled(page)
@@ -864,12 +864,10 @@ def test_a_comment_hidden_by_narrowing_opens_its_inline_reply(browser, serve):
864864
f'.lf-margin-thread .lf-conversation-thread[data-thread="{sent["id"]}"]'
865865
)
866866
expect(inline.locator("textarea")).to_be_focused()
867-
page.locator(".lf-margin-preview").get_by_role(
868-
"button", name="Open this thread in Threads"
869-
).click()
867+
page.locator(".lf-threads-toggle").click()
870868
panel_settled(page)
871-
expect(page.locator(".lf-find-box")).to_have_value("")
872-
expect(page.locator(f'.lf-thread[data-id="{sent["id"]}"]')).to_be_visible()
869+
expect(page.locator(".lf-find-box")).to_have_value("Comment 0")
870+
expect(page.locator(f'.lf-thread[data-id="{sent["id"]}"]')).to_have_count(0)
873871
assert errors == []
874872
page.close()
875873

0 commit comments

Comments
 (0)