From a600aa3698be669a35bf8aa08bb480a3c7d39ba3 Mon Sep 17 00:00:00 2001 From: CRT Date: Mon, 28 Sep 2026 16:42:21 +0000 Subject: [PATCH] runtime column: set the column attributes on scan (config delivered at document start has no yet), no scrollbar in columns, unread only above both the read items and what is on screen, a hidden 1 px webview counts as off screen --- packages/runtime/src/column.ts | 9 ++++++--- packages/runtime/tests/column.test.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/runtime/src/column.ts b/packages/runtime/src/column.ts index 6684812..5a676b2 100644 --- a/packages/runtime/src/column.ts +++ b/packages/runtime/src/column.ts @@ -144,8 +144,9 @@ export function isSourcePage(href: string, source: string): boolean { export type UnreadTracker = { /** * The rendered items, top to bottom, and which of them are on screen right now. The first - * non-empty observation is the baseline (read). Later, an id rendered above the topmost read - * id and not on screen is unread; ids below it are older items (read). + * non-empty observation is the baseline (read). Later, an id rendered above both the topmost + * read id and the topmost item on screen is unread (new, not seen yet); ids below are older + * items (read). */ observe(ordered: readonly string[], onScreen: ReadonlySet): void; /** An item came on screen. */ @@ -174,12 +175,14 @@ export function createUnreadTracker(): UnreadTracker { return; } const topRead = ordered.findIndex(id => read.has(id)); + const topShown = ordered.findIndex(id => onScreen.has(id)); + const limit = topShown >= 0 && topRead >= 0 ? Math.min(topRead, topShown) : topRead; ordered.forEach((id, index) => { if (read.has(id) || unread.has(id)) { if (onScreen.has(id) && unread.delete(id)) remember(read, id); return; } - if (topRead >= 0 && index < topRead && !onScreen.has(id)) remember(unread, id); + if (limit >= 0 && index < limit && !onScreen.has(id)) remember(unread, id); else remember(read, id); }); }, diff --git a/packages/runtime/tests/column.test.ts b/packages/runtime/tests/column.test.ts index f63a5f0..8c0f88b 100644 --- a/packages/runtime/tests/column.test.ts +++ b/packages/runtime/tests/column.test.ts @@ -96,6 +96,18 @@ test('unread: first render is the baseline; new ids above the read ones count un assert.equal(t.nextUnread(['f', 'e']), null); }); +test('unread: a new id below what is on screen is an older item, never unread', () => { + const t = createUnreadTracker(); + t.observe(['a', 'b', 'c'], new Set(['a'])); + // X re-keys or lazily renders an item further down while the top is on screen. + t.observe(['a', 'x', 'b', 'c'], new Set(['a'])); + assert.equal(t.count(), 0); + // Scrolled down (c on screen), a new one on top is unread; one between the top and c is not. + t.observe(['n', 'a', 'y', 'b', 'c'], new Set(['c'])); + assert.equal(t.isUnread('n'), true); + assert.equal(t.isUnread('y'), false); +}); + test('unread: items rendered on screen again are marked read by observe', () => { const t = createUnreadTracker(); t.observe(['a'], new Set());