Skip to content

Commit c2bfa3e

Browse files
fix(app-shell): cited-section locator tells an unlisted same-titled heading from an undrawn one, and opens a heading that reads as nothing at once (#37646)
Fixes #37562 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:使用应用内 AI 的用户,点回答里的“引自记录”引用条打开记录时,若正文里画出了与被引标题同名、但不在目录里的标题,页面立刻打开该字段而不再标记错的那一节;被引标题没有任何文字(只有符号)时,字段也立刻滚到,不再等四秒。 - 为什么做:记录 AI 问询专题里引用定位的两个边角,来自上一轮引用条跟进卡留下的范围说明;本轮按席位裁定,改为用字段自身的渲染解析来数标题。 - 出错会怎样:引用条打开记录时停在字段而不是标题;记录与对话数据不受影响,撤回本次合并即可恢复原样。 - 要你做什么:无。 ## What changes Governing text: scope note 7190147175 on #37487 (N6, N7); seat REWORK 7200445298 on this PR (S1 route ruling, N1, N3) over contract record 7200419777; claim amendment 7200539429 on #37562 (surface widened to `ui/packages/fields`, option A of blocked report 7200523842). **`ui/packages/fields`** (additive): - `widgets/markdownHeadings.ts` (new): `MARKDOWN_REMARK_PLUGINS` (remark-gfm) and `MARKDOWN_REHYPE_PLUGINS` (rehype-sanitize with `RICH_TEXT_SANITIZE_SCHEMA`) are declared here once. `drawnMarkdownHeadings(value)` runs react-markdown with those lists (called as a function, it holds no hooks), reads the tree after the last rehype plugin, and returns each drawn h1-h6 as `{ text, start }`. `start` is the heading's source offset, and it is undefined for the footnote section's `Footnotes` label, which the pipeline adds. - `widgets/MarkdownContent.tsx`: draws with those same constants and re-exports them with `drawnMarkdownHeadings`. Behaviour is unchanged: the same plugin lists, now identity-stable. - `index.tsx`: `loadDrawnMarkdownHeadings()` loads the reader through `MarkdownContent.js`, the module the face already loads on demand. It also exports the `DrawnMarkdownHeading` type. - A first cut imported `markdownHeadings` from the index directly. That made `MarkdownContent` both statically and dynamically imported, and `Build & E2E UI` caught it as an INEFFECTIVE_DYNAMIC_IMPORT on head 6ef69f4. - The final layout keeps exactly one lazy markdown module. Local console build: the ineffective-import ledger reports all pinned, with none new. **`ui/packages/app-shell/src/views/recordSectionAnchor.ts`**: - **S1 / N1, the markdown half** now counts from the parse, not from source lines. `unlisted` = drawn headings of the cited reading whose `start` is not the start of a listed heading of that reading. So it counts what the face draws by construction: - setext headings in a quote or under a comment, a link definition or indented code; - footnote headings and the `Footnotes` label. - Raw heading tags, indented code and a lazy quote over a rule no longer count. - The reader is loaded on demand (`loadSectionHeadingReader`, once; a failed load is retried on the next call). A markdown candidate counted before the load has `unlisted: undefined`, and its count is not trusted. `focusRecordSection` loads the reader, re-counts and tries again. Until then, no heading is marked. - **HTML half**: unchanged. - **N3**: `unlisted > 0` returns `fieldOnly` in `locateSection`'s first condition (one line). The field is then scrolled to as soon as it is drawn, not after the 4 s settle. - **N6 / N7** as before: `counted = unlisted === 0 && drawn.length === count`, and an empty reading is `fieldOnly`. `mayScroll` is unchanged; every scroll still goes through it. - `RecordDetailView.citedSection-37365.test.tsx`: one comment updated (the setext case now scrolls at once). No assertion changed. ## Tests - `fields/src/__tests__/markdownHeadings-37562.test.tsx` (new). Every shape is pinned twice: against the reader and against the face's own DOM (`MarkdownContent` rendered). - S1, drawn and answered: setext in a quote; setext under a comment line; under a link definition; under indented code; footnote ATX plus the `Footnotes` h2; ATX behind a quote or a list marker. - N1, never drawn and not answered: a raw heading tag, an indented code line, a lazy quote over a rule, fenced code. - Also pinned: `start` offsets, the `Footnotes` label's undefined `start`, and that the index loader resolves the same function. - `app-shell/src/views/recordSectionAnchor.test.tsx`: - S1: ten shape rows count `unlisted: 1`, plus the `Footnotes` label against a cited `Footnotes` (CONTROL: no footnote, 0). - N1: five rows count 0. - The html rows are kept. - A fresh-module case: before the parse loads the count is undefined and no heading is marked; once it loads the heading is marked and scrolled once. This case caught a real bug in the first cut. - N3 with fake timers: a scroll at once. CONTROL: an undrawn titled heading still waits for the settle. - The N6 and N7 cases are kept. - Ablation, parse-based count (`scripts/ablation-replace.mjs`, anchor ` return readDrawnMarkdown(value).filter(` -> ` return 0 * readDrawnMarkdown(value).filter(`, blob c5fa5fb -> f483a359da34). Result: Tests 14 failed | 25 passed, red on the N6 pair case, the old setext case, all ten S1 rows, the `Footnotes` row and N3; the N1 rows stay green as expected. Restored: blob == HEAD and `git diff HEAD` empty. - Earlier ablations (N6 count guard, N7 `fieldOnly`): see the first round, unchanged code paths. ## Acceptance notes - N2 (the outline reads source text, the page reads rendered text) is not done here; the seat files it. The unlisted count compares starts per reading, so a listed heading drawn under another reading counts as unlisted. That closes the wrong-section half of N2 for this guard only, not the mismatch itself. - With the parse, the exact drawn index of the cited heading is now knowable; marking it despite unlisted headings is possible. It is left as the field, per N3. - `MarkdownContent.tsx` gains two react-refresh `only-export-components` warnings for the re-exported constants (warn level; the index already carries many). ## Verification Two-minute check: `cd ui && pnpm exec vitest run packages/fields/src/__tests__/markdownHeadings-37562.test.tsx packages/app-shell/src/views/recordSectionAnchor.test.tsx`. Expect all passed. Read first, in order: 1. `fields/src/widgets/markdownHeadings.ts` (the risk: a tree read that differs from what is drawn). 2. `recordSectionAnchor.ts` `unlistedMarkdownCount` / `withUnlistedCount` and the load path in `focusRecordSection`. 3. `fields/src/index.tsx` `loadDrawnMarkdownHeadings` (lazy-chunk shape). <details><summary>Readings, head c3f7728 (tree objectstack-ai/objectstack)</summary> - `vitest run` recordSectionAnchor.test.tsx + RecordDetailView.citedSection-37365.test.tsx + markdownHeadings-37562.test.tsx + markdownCellHeading-36344.test.tsx: Test Files 4 passed (4), Tests 69 passed (69); lock VERDICT command-exit 0. - Full `@object-ui/fields` suite (taken at 6ef69f4; the head commit after it moves the plugin lists between two fields modules, and the four files above were rerun on it): Test Files 333 passed | 1 skipped (334), Tests 5085 passed | 7 skipped; VERDICT command-exit 0. - Full `@object-ui/app-shell` suite: not run locally (2452 files, over an hour on the shared lock last round). CI `Test UI` covers it: every shard green on this head. - `type-check` of `@object-ui/fields` and `@object-ui/app-shell` (both programs each): VERDICT command-exit 0. - Console `vite build`, local: ineffective-dynamic-import ledger: 40 ineffective dynamic imports, all pinned, none new. Eager closure 120/2610 chunks, 1992997 bytes gzipped. The same build on base b1c41e5 (fields and anchor sources restored from it) gives 120/2610 chunks, 1992700 bytes: +297 bytes, no new eager chunk. `vendor-react-markdown` is eager on both. `pnpm check:eager-closure`: 1946.3 KB of 2431.6 KB budget. - `dispatch-gates --commands`: 39 derived (9 paths); 38 run on this head plus `check:changeset-fixed`, all exit 0. `pnpm --dir ui exec vitest run scripts/` (at 6ef69f4): 172 passed | 2 skipped. `--ran` verdict: 39 derived families accounted for, 39 run, 0 NOT-MEASURED. - `overlap-check --branch=HEAD`: VERDICT clean exit 0. - CI on c3f7728: 44 success / 13 skipped / 0 failure. Lint & Repo Gates, TypeScript Type Check, Test Core, Governed Surface Queue Guard, Lint UI, Type Check UI, Test UI (15 shard runs, all success), Build & E2E UI, Live E2E UI, Dogfood Regression Gate, Check Changeset and Type Check · debt ledger all succeeded; Build Core was skipped. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6d106a1 commit c2bfa3e

9 files changed

Lines changed: 483 additions & 30 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/fields': patch
3+
---
4+
5+
feat(fields): read the headings a markdown value's document face draws, from the face's own parse
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
`@object-ui/fields` exports `loadDrawnMarkdownHeadings()`, which loads on demand and answers `drawnMarkdownHeadings(value)`: each heading the markdown `document` face draws, with its text and where it starts in the value (none for the footnote section's `Footnotes` label, which the pipeline adds), and the `DrawnMarkdownHeading` type. It runs the face's own pipeline (react-markdown with the GitHub Flavored Markdown and sanitize plugins `MarkdownContent` draws with), so a reader that must agree with the drawn page counts what is drawn by construction, and react-markdown stays in the lazy chunk the face already lives in. The face draws exactly as before.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): a record opened at a cited section no longer marks a same-titled heading the outline does not list, and opens its field at once when no heading can be told apart
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A record opened from a citation chip (`?section=ANCHOR`) finds the cited heading among the field's drawn headings that read the same, by count. When the body draws both a same-titled heading the outline does not list (a setext heading, one in a quote, a list item or a footnote, the footnote section's label) and a listed heading the face does not draw (one inside a raw HTML block), the two counts agreed while the index pointed at the wrong heading. A markdown body's unlisted headings are now counted from the field's own parse (`@object-ui/fields`' `loadDrawnMarkdownHeadings`, loaded on demand), so they are the headings the face draws; an html body's from its heading tags. When the body draws one, the field is opened instead of a heading that may be another section. That field, like the field of a cited heading with no letter or digit, is now scrolled to as soon as it is drawn instead of after the four-second settle; a titled heading that is not drawn yet still waits for it.

‎ui/packages/app-shell/src/views/RecordDetailView.citedSection-37365.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ describe('a record opened at a cited section (objectstack#37365)', () => {
239239
const field = () => dup.container.querySelector<HTMLElement>('[data-detail-field="content"]');
240240
await waitFor(() => expect(field()?.querySelectorAll('h1')).toHaveLength(2), { timeout: 4000 });
241241
// Both drawn headings read `Scope`; the outline lists one. Nothing is
242-
// marked, and once the settle (RECORD_SECTION_SETTLE_MS) passes the field
243-
// is scrolled to.
242+
// marked, and the field is scrolled to: at once, since the face's parse
243+
// draws a same-titled heading the outline does not list (objectstack#37562 N3).
244244
expect(marked(dup.container)).toHaveLength(0);
245245
await waitFor(() => expect(scrolled).toEqual([field()]), { timeout: 7000 });
246246
expect(marked(dup.container)).toHaveLength(0);

‎ui/packages/app-shell/src/views/recordSectionAnchor.test.tsx‎

Lines changed: 139 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
* draws a different number of same-titled headings than the outline lists, the
1313
* field is opened rather than a heading that may be another one.
1414
*/
15-
import { afterEach, describe, expect, it, vi } from 'vitest';
15+
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
1616
import { headingsOf } from '@objectstack/spec/ai';
1717
import {
1818
RECORD_SECTION_TARGET_ATTR,
1919
focusRecordSection,
20+
loadSectionHeadingReader,
2021
locateSection,
2122
sectionCandidates,
2223
} from './recordSectionAnchor';
@@ -43,6 +44,9 @@ function row(field: string, inner: string): string {
4344
return `<div data-detail-field="${field}">${inner}</div>`;
4445
}
4546

47+
// The markdown face's parse, loaded once, as the record page loads it.
48+
beforeAll(() => loadSectionHeadingReader());
49+
4650
afterEach(() => {
4751
document.body.innerHTML = '';
4852
vi.useRealTimers();
@@ -60,24 +64,24 @@ describe('objectstack#37365 — sectionCandidates derives the anchor as the serv
6064
const server = headingsOf(MARKDOWN, false).map((h) => h.anchor);
6165
expect(server).toEqual(['intro', 'scope', 'scope-2']);
6266
expect(sectionCandidates(FIELDS, RECORD, 'scope')).toEqual([
63-
{ field: 'content', face: 'markdown', reading: 'scope', ordinal: 0, count: 2 },
67+
{ field: 'content', face: 'markdown', reading: 'scope', ordinal: 0, count: 2, unlisted: 0 },
6468
]);
6569
expect(sectionCandidates(FIELDS, RECORD, 'scope-2')).toEqual([
66-
{ field: 'content', face: 'markdown', reading: 'scope', ordinal: 1, count: 2 },
70+
{ field: 'content', face: 'markdown', reading: 'scope', ordinal: 1, count: 2, unlisted: 0 },
6771
]);
6872
});
6973

7074
it('reads an html body as html', () => {
7175
expect(headingsOf(HTML, true).map((h) => h.anchor)).toContain('data-privacy');
7276
expect(sectionCandidates(FIELDS, RECORD, 'data-privacy')).toEqual([
73-
{ field: 'legal', face: 'html', reading: 'dataprivacy', ordinal: 0, count: 1 },
77+
{ field: 'legal', face: 'html', reading: 'dataprivacy', ordinal: 0, count: 1, unlisted: 0 },
7478
]);
7579
});
7680

7781
it('a `textarea` body is a candidate drawn as text', () => {
7882
const record = { ...RECORD, summary: '# Steps\n\nDo it.' };
7983
expect(sectionCandidates(FIELDS, record, 'steps')).toEqual([
80-
{ field: 'summary', face: 'text', reading: 'steps', ordinal: 0, count: 1 },
84+
{ field: 'summary', face: 'text', reading: 'steps', ordinal: 0, count: 1, unlisted: 0 },
8185
]);
8286
});
8387

@@ -109,7 +113,7 @@ describe('objectstack#37365 — locateSection finds the drawn heading', () => {
109113
const body = ['Scope', '=====', '', 'x', '', '# Scope', '', 'y'].join('\n');
110114
expect(headingsOf(body, false).map((h) => h.anchor)).toEqual(['scope']);
111115
const candidates = sectionCandidates(FIELDS, { content: body }, 'scope');
112-
expect(candidates).toEqual([{ field: 'content', face: 'markdown', reading: 'scope', ordinal: 0, count: 1 }]);
116+
expect(candidates).toEqual([{ field: 'content', face: 'markdown', reading: 'scope', ordinal: 0, count: 1, unlisted: 1 }]);
113117
document.body.innerHTML = row('content', '<h1 id="setext">Scope</h1><p>x</p><h1 id="atx">Scope</h1><p>y</p>');
114118
const target = locateSection(document.body, candidates);
115119
expect(target?.field.getAttribute('data-detail-field')).toBe('content');
@@ -136,6 +140,91 @@ describe('objectstack#37365 — locateSection finds the drawn heading', () => {
136140
expect(locateSection(document.body, sectionCandidates(FIELDS, { content: control }, 'scope'))?.heading?.id).toBe('real');
137141
});
138142

143+
it('objectstack#37562 N6 — one unlisted same-titled heading plus one listed-but-undrawn heading opens the field, never a heading; CONTROL: the first Scope a paragraph line, the cited heading is marked', () => {
144+
// A setext `Scope` the outline does not list, and `# Scope` inside a raw
145+
// HTML block that the outline lists and the face does not draw: the face
146+
// draws two `Scope`s and the outline lists two, so the count agrees while
147+
// index 0 of the drawn ones is the setext heading, not the cited one.
148+
const body = ['Scope', '=====', '', 'x', '', '<div>', '# Scope', '</div>', '', '# Scope', '', 'y'].join('\n');
149+
expect(headingsOf(body, false).map((h) => h.anchor)).toEqual(['scope', 'scope-2']);
150+
document.body.innerHTML = row(
151+
'content',
152+
'<h1 id="setext">Scope</h1><p>x</p><div># Scope</div><h1 id="atx">Scope</h1><p>y</p>',
153+
);
154+
for (const anchor of ['scope', 'scope-2']) {
155+
const candidates = sectionCandidates(FIELDS, { content: body }, anchor);
156+
expect(candidates).toEqual([
157+
{ field: 'content', face: 'markdown', reading: 'scope', ordinal: anchor === 'scope' ? 0 : 1, count: 2, unlisted: 1 },
158+
]);
159+
const target = locateSection(document.body, candidates);
160+
expect(target?.field.getAttribute('data-detail-field')).toBe('content');
161+
expect(target?.heading).toBeUndefined();
162+
}
163+
// CONTROL: the first `Scope` a paragraph line, which no face draws as a
164+
// heading; with the HTML block gone the outline and the face agree.
165+
const control = ['Scope', '', 'x', '', '# Scope', '', 'y'].join('\n');
166+
expect(sectionCandidates(FIELDS, { content: control }, 'scope')).toEqual([
167+
{ field: 'content', face: 'markdown', reading: 'scope', ordinal: 0, count: 1, unlisted: 0 },
168+
]);
169+
document.body.innerHTML = row('content', '<p>Scope</p><p>x</p><h1 id="atx">Scope</h1><p>y</p>');
170+
expect(locateSection(document.body, sectionCandidates(FIELDS, { content: control }, 'scope'))?.heading?.id).toBe('atx');
171+
});
172+
173+
it.each([
174+
['a setext heading', ['Scope', '-----']],
175+
['a two-line setext heading', ['Sco', 'pe', '===']],
176+
['a setext heading inside a quote', ['> Scope', '> ---']],
177+
['a setext heading under a comment line', ['<!-- note -->', 'Scope', '---']],
178+
['a setext heading under a link definition', ['[a]: https://example.com', 'Scope', '===']],
179+
['a setext heading under indented code', [' code', 'Scope', '---']],
180+
['an ATX heading behind a quote', ['> # Scope']],
181+
['an ATX heading in a list item', ['1. ## Scope']],
182+
['an ATX heading behind blanks', [' # Scope']],
183+
['an ATX heading in a footnote', ['x[^1]', '', '[^1]: # Scope']],
184+
])('objectstack#37562 S1 — %s, which the face draws, counts as unlisted', (_shape, lines) => {
185+
const value = [...lines, '', '# Scope'].join('\n');
186+
expect(sectionCandidates(FIELDS, { content: value }, 'scope')[0]?.unlisted).toBe(1);
187+
});
188+
189+
it("objectstack#37562 S1 — the footnote section's Footnotes label counts against a cited `Footnotes`; CONTROL: with no footnote, none", () => {
190+
const value = ['# Footnotes', '', 'x[^1]', '', '[^1]: y'].join('\n');
191+
expect(sectionCandidates(FIELDS, { content: value }, 'footnotes')[0]?.unlisted).toBe(1);
192+
expect(sectionCandidates(FIELDS, { content: '# Footnotes\n\nx' }, 'footnotes')[0]?.unlisted).toBe(0);
193+
});
194+
195+
it.each([
196+
['a raw heading tag', ['<h2>Scope</h2>']],
197+
['an indented code line', [' # Scope']],
198+
['a lazy quote line over a rule', ['> Scope', '---']],
199+
['fenced code', ['```', 'Scope', '===', '> # Scope', '```']],
200+
['other titles, a rule under a blank line, a plain list item', ['Preface', '=======', '', '> # Intro', '', '---', '', '- Scope']],
201+
])('objectstack#37562 N1 — %s, which the face never draws, does not count', (_shape, lines) => {
202+
const value = [...lines, '', '# Scope'].join('\n');
203+
expect(sectionCandidates(FIELDS, { content: value }, 'scope')[0]?.unlisted).toBe(0);
204+
});
205+
206+
it('an html body counts a heading tag left unclosed or opened inside another; CONTROL: hr and header tags count none', () => {
207+
const unlisted = (value: string): number | undefined => sectionCandidates(FIELDS, { legal: value }, 'scope')[0]?.unlisted;
208+
expect(unlisted('<h2>Scope</h2><p>x</p><h2>Scope')).toBe(1);
209+
expect(unlisted('<h2>About <h2>Scope</h2><h2>Scope</h2>')).toBe(1);
210+
expect(unlisted('<h2>Scope</h2><hr><header>Scope</header>')).toBe(0);
211+
});
212+
213+
it('objectstack#37562 — before the face’s parse loads, a markdown count is not trusted; once it loads, the heading is marked', async () => {
214+
vi.resetModules();
215+
const fresh = await import('./recordSectionAnchor');
216+
const candidates = fresh.sectionCandidates(FIELDS, RECORD, 'scope');
217+
expect(candidates[0].unlisted).toBeUndefined();
218+
document.body.innerHTML = row('content', '<h1>Intro</h1><h2 id="s">Scope</h2><h2>Scope</h2>');
219+
expect(fresh.locateSection(document.body, candidates)?.heading).toBeUndefined();
220+
const heading = document.getElementById('s')!;
221+
heading.scrollIntoView = vi.fn();
222+
fresh.focusRecordSection(document.body, candidates, 5000);
223+
expect(heading.hasAttribute(RECORD_SECTION_TARGET_ATTR)).toBe(false);
224+
await vi.waitFor(() => expect(heading.getAttribute(RECORD_SECTION_TARGET_ATTR)).toBe('true'), { timeout: 5000 });
225+
expect(heading.scrollIntoView).toHaveBeenCalledTimes(1);
226+
});
227+
139228
it('a heading with no letter or digit opens the field; CONTROL: a titled heading beside it is marked', () => {
140229
const body = ['# ???', '', 'x', '', '# Intro', '', 'y'].join('\n');
141230
const [blank, intro] = headingsOf(body, false);
@@ -200,6 +289,50 @@ describe('objectstack#37365 — focusRecordSection', () => {
200289
expect(document.querySelector(`[${RECORD_SECTION_TARGET_ATTR}]`)).toBeNull();
201290
});
202291

292+
it('objectstack#37562 N7 — a heading that reads as nothing scrolls to the field at once; CONTROL: a titled heading not yet drawn still waits for the settle', () => {
293+
vi.useFakeTimers();
294+
const body = ['# ???', '', 'x', '', '# Intro', '', 'y'].join('\n');
295+
const [blank, intro] = headingsOf(body, false);
296+
document.body.innerHTML = row('content', '<p>loading</p>');
297+
const field = document.querySelector<HTMLElement>('[data-detail-field="content"]')!;
298+
const scroll = vi.fn();
299+
field.scrollIntoView = scroll;
300+
focusRecordSection(document.body, sectionCandidates(FIELDS, { content: body }, blank.anchor), 50);
301+
expect(scroll).toHaveBeenCalledTimes(1);
302+
vi.advanceTimersByTime(60);
303+
expect(scroll).toHaveBeenCalledTimes(1);
304+
expect(document.querySelector(`[${RECORD_SECTION_TARGET_ATTR}]`)).toBeNull();
305+
// CONTROL: `Intro` is not drawn yet, so the page waits for it until the settle.
306+
scroll.mockClear();
307+
focusRecordSection(document.body, sectionCandidates(FIELDS, { content: body }, intro.anchor), 50);
308+
expect(scroll).not.toHaveBeenCalled();
309+
vi.advanceTimersByTime(60);
310+
expect(scroll).toHaveBeenCalledTimes(1);
311+
});
312+
313+
it('objectstack#37562 N3 — a body drawing a same-titled heading the outline does not list scrolls to the field at once; CONTROL: without it, an undrawn heading still waits for the settle', () => {
314+
vi.useFakeTimers();
315+
const body = ['Scope', '=====', '', 'x', '', '# Scope', '', 'y'].join('\n');
316+
document.body.innerHTML = row('content', '<h1>Scope</h1><p>x</p><h1>Scope</h1><p>y</p>');
317+
const field = document.querySelector<HTMLElement>('[data-detail-field="content"]')!;
318+
const scroll = vi.fn();
319+
field.scrollIntoView = scroll;
320+
focusRecordSection(document.body, sectionCandidates(FIELDS, { content: body }, 'scope'), 50);
321+
expect(scroll).toHaveBeenCalledTimes(1);
322+
vi.advanceTimersByTime(60);
323+
expect(scroll).toHaveBeenCalledTimes(1);
324+
expect(document.querySelector(`[${RECORD_SECTION_TARGET_ATTR}]`)).toBeNull();
325+
// CONTROL: the setext heading titled otherwise and `Scope` not drawn yet.
326+
scroll.mockClear();
327+
document.body.innerHTML = row('content', '<h1>Preface</h1><p>x</p><p>loading</p>');
328+
document.querySelector<HTMLElement>('[data-detail-field="content"]')!.scrollIntoView = scroll;
329+
const control = ['Preface', '=======', '', 'x', '', '# Scope', '', 'y'].join('\n');
330+
focusRecordSection(document.body, sectionCandidates(FIELDS, { content: control }, 'scope'), 50);
331+
expect(scroll).not.toHaveBeenCalled();
332+
vi.advanceTimersByTime(60);
333+
expect(scroll).toHaveBeenCalledTimes(1);
334+
});
335+
203336
it('a heading never drawn settles on the field, with no error', () => {
204337
vi.useFakeTimers();
205338
document.body.innerHTML = row('content', '<p>Scope is not a heading here</p>');

0 commit comments

Comments
 (0)