runtime column: set the column attributes on scan (config delivered at document start has no <html> 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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67851cd8f5
commit
abdc29ba55
2 changed files with 18 additions and 3 deletions
|
|
@ -144,8 +144,9 @@ export function isSourcePage(href: string, source: string): boolean {
|
||||||
export type UnreadTracker = {
|
export type UnreadTracker = {
|
||||||
/**
|
/**
|
||||||
* The rendered items, top to bottom, and which of them are on screen right now. The first
|
* 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
|
* non-empty observation is the baseline (read). Later, an id rendered above both the topmost
|
||||||
* id and not on screen is unread; ids below it are older items (read).
|
* 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<string>): void;
|
observe(ordered: readonly string[], onScreen: ReadonlySet<string>): void;
|
||||||
/** An item came on screen. */
|
/** An item came on screen. */
|
||||||
|
|
@ -174,12 +175,14 @@ export function createUnreadTracker(): UnreadTracker {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const topRead = ordered.findIndex(id => read.has(id));
|
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) => {
|
ordered.forEach((id, index) => {
|
||||||
if (read.has(id) || unread.has(id)) {
|
if (read.has(id) || unread.has(id)) {
|
||||||
if (onScreen.has(id) && unread.delete(id)) remember(read, id);
|
if (onScreen.has(id) && unread.delete(id)) remember(read, id);
|
||||||
return;
|
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);
|
else remember(read, id);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -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);
|
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', () => {
|
test('unread: items rendered on screen again are marked read by observe', () => {
|
||||||
const t = createUnreadTracker();
|
const t = createUnreadTracker();
|
||||||
t.observe(['a'], new Set());
|
t.observe(['a'], new Set());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue