diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md new file mode 100644 index 00000000..2f0535ee --- /dev/null +++ b/client/src/collapsing-headings-spec.md @@ -0,0 +1,245 @@ +The CodeChat Editor, a word processor for software developers.
Copyright (C) +2024-2026 Bryan A. Jones. + +This file is part of the CodeChat Editor. + +The CodeChat Editor is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) any +later version. + +The CodeChat Editor is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with the +CodeChat Editor. If not, see +[http://www.gnu.org/licenses](http://www.gnu.org/licenses). + +Collapsing headings spec +======================== + +Each heading in a document gets a disclosure marker (▾) before its text that +collapses its section: all content after the heading and before the next heading +of the same or a higher level, including subheadings, doc blocks and code +blocks. The heading itself stays visible. The marker then changes to ▸, which +shows the section again. This lets a reader fold away the parts of a long +document or source file they aren't working on. + +Collapsing changes only what the Client shows; nothing about it is saved (rule +6). + +Definitions +----------- + +* **Heading:** an `

`–`

` element that, ignoring generated elements (rule + 1), is a direct child of the contents of a Markdown document + (`.CodeChat-doc-contents` in [CodeChatEditor.mts](CodeChatEditor.mts)) or of a + doc block (the `.CodeChat-doc-contents` of a `DocBlockWidget` in + [CodeMirror-integration.mts](CodeMirror-integration.mts)). A heading inside a + list, block quote or table isn't one. A heading rendered from a Rust comment + such as `/// # Examples` qualifies on the same basis. +* **Doc block:** documentation that the Server renders as editable HTML in a + source file. Code between doc blocks stays in CodeMirror; heading-like text + in that code isn't a heading. +* **Level:** the heading's number: `

` is level 1, the highest. +* **Document order:** in Markdown, the order of the document's contents; in a + source file, the order of code and doc blocks, including the order of + elements inside each doc block. +* **Section:** everything after a heading in document order, up to but not + including the next heading at the same or a higher level (a lower or equal + number), or to the end of the document. The heading itself isn't part of its + section. A section may be empty. +* **Heading key:** the tuple of a heading's level, its text, and its occurrence + among headings with that same level and text in document order. The text is + the heading's `textContent` as the Client would send it to the Server (no + generated elements, math not yet rendered), with each run of whitespace, + including non-breaking spaces, collapsed to one space. This key only restores + collapsed state after content is replaced (rules 8 and 9); it isn't saved. +* **Cursor:** TinyMCE's, while it has the text cursor; otherwise, in a source + file, the head of CodeMirror's main selection. Focusing a summary neither + moves the cursor nor reports a different one to the IDE. + +Rules +----- + +1. **Disclosure:** each heading is followed by a view-only `
` element + which holds the rest of the heading's section in the same Markdown document + or doc block, including any subheadings and their own `
`. Its + `` holds only the marker, shown before the heading text: ▾ when + open, ▸ when closed. These are the *generated elements*. The heading itself + stays outside them, so it remains editable and remains a heading for screen + readers. In a source file, the same summary also controls the rest of the + section (rule 5). + Visible summaries, including those in inactive doc blocks, can be reached + and left with the keyboard, but can't hold the text cursor; focusing one + leaves TinyMCE in its current block. A click, Enter or Space on a summary + toggles it without editing the document, including in a read-only Client. + Its accessible name identifies the heading, and its state is exposed through + the native disclosure semantics. +2. **Collapse:** closing the disclosure hides the heading's section. The heading + and its summary stay visible. Before closing, if the cursor or either end of + its selection is in the section being hidden, clear the selection and move + the cursor to the end of the heading, without taking focus from the + activating summary. In a source file, if TinyMCE isn't in the heading's doc + block, CodeMirror's cursor moves to the start of that doc block instead. +3. **Expand:** activating ▸ shows the section again. A subheading that was + collapsed before stays collapsed and keeps its section hidden, including code + which both sections contain. +4. **Markdown documents:** the whole section is in the heading's `
`. +5. **Source files:** a section may start or end inside a doc block; hiding part + of a doc block leaves its other content visible. Code in a collapsed section + is hidden, not deleted. From the section's first code, its code and whole doc + blocks are folded with CodeMirror's own folding, so each outermost collapsed + section shows as one fold placeholder (…), or none if it has no code. + Clicking a placeholder expands its section and no other. Removing the fold + with the fold gutter, Unfold Code or Unfold All expands its section too. +6. **Never saved:** collapsing and expanding change only the Client's view; they + do not mark the document as edited, send document content or add undo + entries. The generated elements, their state and any other collapse-only + markup are absent from content sent to the Server and from copied content. + Original markup and attributes, including heading ids and any author-written + disclosure elements, are preserved. Cursor paths and offsets describe the + document without the generated elements. Moving the cursor under rule 2 may + send a normal cursor update. +7. **Cursor in hidden content:** the cursor never stays in hidden content. When + it moves there, every collapsed section hiding it opens. This is a design + decision; the alternative was to keep the section collapsed and move the + cursor past the fold. Opening it matches how CodeMirror's folding already + treats code, so collapsed sections and code folds behave the same across the + Client's UI. This covers the cursor the IDE sends, go-to-line, a search's + current match (including TinyMCE's search), and a Client edit or Server + update that leaves the cursor in a collapsed section. Following a link or + cross-reference opens every section hiding its target. If the browser opens a + generated `
`, such as for its own find, the section expands. A line + in a partly hidden doc block points to that doc block, which is visible, so + it opens nothing. A scroll position alone never opens a section. Two of these + cases need fixes in the Client first; this spec assumes they will be made + (see the TODOs in Implementation). +8. **Edits:** outside a summary, the generated elements don't change what any + key or edit does. Before a Client edit that would change hidden content, + expand every section needed to reveal it, then apply the edit. This includes + Backspace or Delete merging across a collapsed section and replacing or + deleting a selection that crosses one. Undo and redo are edits too. + A section follows its heading through Client edits. Editing the heading's + text preserves its collapsed state; changing its level recomputes its end. + Deleting a heading or turning it into ordinary text removes its collapsed + state, though other collapsed headings may still hide its former content. A + new heading starts expanded; if a heading is split, its first part keeps the + state. Undo and redo replace content, so they restore collapsed state by + heading key, as in rule 9. +9. **Lifetime:** collapsed state lasts only while the file is open in the + Client. On each content update from the Server, retain the keys of + collapsed headings before applying the update and restore collapsed state + to the headings with matching keys afterwards, before resolving cursor and + scroll targets (rule 7). This covers edits made in the IDE and the + re-translations the Server sends on its own, whether they change part of the + content or replace all of it. Headings with no matching key start expanded, + though a collapsed ancestor may still hide them. Identical headings may + therefore swap state, and a heading which is renamed, changes level or takes + its text from a changed cross-reference may lose it. + +Out of scope +------------ + +* Remembering collapsed sections after the file is closed or the Client reloads. +* New commands to collapse or expand every section at once. +* Changing CodeMirror's folding by syntax, which keeps working alongside the + folds that collapsed sections add. +* Making the browser's own find reach folded content. + +Examples +-------- + +`H1 A` is a level-1 heading with text `A`; `p1` is a paragraph; `code1` is a +code block. Examples whose Document cell starts with "Source file:" describe a +source file; every other example is a Markdown document. Each example starts +with every section shown unless its Document cell specifies otherwise. Results +describe visible content and any observable save or synchronization behavior; +`…` is CodeMirror's fold placeholder (rule 5). + +These examples show the main behavior. Unusual cases, such as the cursor move in +rule 2, saves and dirty state in source files, new headings, undo and redo, and +TinyMCE's search, aren't listed here. The implementation must add tests for +them, and for the examples, to the Client tests in +[CodeChatEditor-test.mts](CodeChatEditor-test.mts) or, where a test needs the +Server, to the browser tests in [overall](../../server/tests/overall/). + +| # | Document | Action | Expected result | +| -- | -- | -- | -- | +| 1 | `H1 A`, `p1`, `H2 B`, `p2`, `H1 C`, `p3` | Collapse A | `H1 A`, `H1 C`, `p3` | +| 2 | Same as 1 | Collapse B, collapse A, expand A | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` (B stays collapsed) | +| 3 | Source file: doc block [`H1 A`, `p1`], `code1`, doc block [`H2 B`], `code2`, doc block [`H1 C`] | Collapse A | Doc block [`H1 A`], `…`, doc block [`H1 C`] | +| 4 | Source file: doc block [`H2 A`, `p1`], `code1`, doc block [`p2`, `H2 B`, `p3`] | Collapse A | Doc block [`H2 A`], `…`, doc block [`H2 B`, `p3`] | +| 5 | Same as 1, initially clean | Collapse A, then expand A without editing | No document content sent; no dirty state | +| 6 | Same as 1 | Collapse A, edit p3, wait for autosave | Outgoing document HTML and the saved file equal those from the same edit with A shown; p1, B and p2 remain in the document | +| 7 | Same as 3, A collapsed | The IDE moves the cursor into `code1` | A opens; the cursor is in `code1` | +| 8 | Same as 1, A collapsed | Backspace at the start of C in the Client | A opens before C merges into p2; result equals the same edit with A shown | +| 9 | Same as 1, A collapsed, cursor in A | The IDE inserts a paragraph above A | New paragraph, `H1 A`, `H1 C`, `p3`; A remains collapsed | +| 10 | Same as 1, A collapsed | Edit p3 so that the Server's reply to the autosave changes the content (for example, a line it re-wraps), and wait for that update | The update replaces the content; A remains collapsed and p3 shows the Server's version | +| 11 | Source file: doc block [`H1 A`], doc block [`p1`], `code1`, doc block [`H1 B`], `code2`, doc block [`H1 C`]; A and B collapsed | Click the placeholder after B | Doc block [`H1 A`], `…`, doc block [`H1 B`], `code2`, doc block [`H1 C`] | + +Implementation +-------------- + +These constraints come from reading the Client and from running CodeMirror +(`@codemirror/language` 6.13.1) and TinyMCE 8.10.1. + +* **`
` in TinyMCE** ([CodeChatEditor.mts](CodeChatEditor.mts) for + Markdown documents; doc blocks behave the same): + * TinyMCE cancels every click inside a `
`, and treats Enter or Space + in a `` as typing. The Client must handle these events on its own + summaries before TinyMCE does, and set `open` itself. + * TinyMCE gives the edges of a `
`, even an open one, their own + behavior: Backspace and Delete don't cross them, Enter in an empty last + paragraph leaves the `
`, and the down arrow at the end of the + document's last one adds a paragraph. To avoid this (rule 8), remove the + generated elements first, keeping the content, and add them again + afterwards. TinyMCE also outlines a `
` that holds the cursor. + * Undo levels, raw saves, `innerHTML` reads and copied selections include the + generated elements and their state, so remove them from each (rule 6). For + example, an arrow key after a toggle adds an undo level and marks the + document as edited. + * TinyMCE's `searchreplace` marks matches in a closed `
` without + opening it, and selects one only when its dialog closes. Open the section + holding the current match (rule 7); replacing is an edit (rule 8). +* **Folds in source files** + ([CodeMirror-integration.mts](CodeMirror-integration.mts)): use the folding in + `@codemirror/language`, which `basicSetup` already includes; see its + [reference](https://codemirror.net/docs/ref/#language.foldEffect). + * A fold that starts at a doc block leaves that block visible and draws no + placeholder. So start a section's fold at its first code, and hide the doc + blocks before that code like parts of doc blocks. + * Compute the folds from the set of collapsed headings, folding only the + outermost collapsed sections. A fold mapped through a diff can go stale, so + after a toggle or an update, remove all section folds with `unfoldEffect`, + then add the recomputed ones with `foldEffect`, in document order. + * The default placeholder opens the first fold in its line block, and adjacent + sections share a line block. Give each placeholder, including those of folds + by syntax, its own fold, using `codeFolding`'s `preparePlaceholder` and + `placeholderDOM` (rule 5). + * `foldState` opens a fold when the selection's head moves strictly inside it, + so not at its first position, at the end of a file whose last section is + collapsed, or in a doc block hidden before it. When `scrollToLine`, + go-to-line or search puts the cursor there, the Client must open the section + (rule 7). Arrow keys use a fold's first position as the end of the visible + doc block before it (`selectDocBlockEdge`); that doesn't open it. + * `foldState` opens a touched fold for deletions only. Open it for every other + Client edit too, including typing, paste, undo, redo and Replace All + (rule 8). Updates from the Server are exempt. +* **Hidden parts of doc blocks:** change the shown block in place. A redraw + isn't reliable (`DocBlockWidget.eq` ignores collapsed state, and `updateDOM` + skips the block edited in TinyMCE) and loses the summary's focus. Add the + generated elements again wherever the Client rebuilds a block's contents. +* **Updates from the Server:** after each one, restore collapsed state by + heading key (rule 9), leaving out every section that would hide the update's + cursor or, if it has none, the Client's (rule 7). +* **Links and the IDE's cursor:** TODO: apply rule 7 to the IDE's cursor in + Markdown documents once the Client follows it there (`scrollToLine` in + [CodeChatEditor.mts](CodeChatEditor.mts) is a `TODO`). TODO: once same-file + links work in source files (the ignored tests in + [overall_5.rs](../../server/tests/overall/overall_5.rs)), find a link's target + in the doc-block contents held in CodeMirror's state, since `followLink`'s + `document.querySelector` can't see folded content, and open the sections + hiding it. In Markdown documents, `followLink` must open them too. diff --git a/submission.md b/submission.md new file mode 100644 index 00000000..43cdbc11 --- /dev/null +++ b/submission.md @@ -0,0 +1,322 @@ +Project 2 submission +==================== + +Team name: Collapsing headings 1 + +The specification consists of the file +[client/src/collapsing-headings-spec.md](client/src/collapsing-headings-spec.md). + +Draft submission +---------------- + +### Askar Oralkhan + +GitHub userid: askaroralkhan + +#### Contributions + +Wrote the first draft of the spec, ran the five spec review rounds and split +their findings among the team, simplified rules 7 and 9 after round 2, rewrote +rules 5, 7 and 9 and the Implementation section around CodeMirror's folding +after round 3, applied rounds 4 and 5, and wrote this file and the pull request. + +#### Build and run test + +Prompting Claude Opus 5.5, high effort (Claude Code 2.1.330), started in the +repo root at 8d47bd5, with "Verify that you can build and run the project in +the current git repo." reported that the project builds and runs: + +* **Build:** `./bt build` finished without errors (cargo and rustc 1.100.0, + node 25.9.0, pnpm 12.21.0). It built the Server, the Client, the TypeScript + bindings (13 of 13 binding-export tests passed) and the VSCode extension + (esbuild bundle and a clean `tsc -noEmit`). +* **Run:** it started the standalone Server with + `cargo run --bin codechat-editor-standalone -- --port 18080 serve`. + `GET /ping` returned 200, and requesting the project's `toc.md` returned 200 + with the rendered HTML. It then stopped the Server. +* It didn't run `./bt test`, whose browser integration tests are slow. It + noted one compiler warning (`server/src/webserver.rs:2023`) and that the + build leaves an untracked native module in `extensions/VSCode/src/`. + +#### Specification review rounds + +Each round was a fresh, headless Claude Code session in a throwaway worktree +of the reviewed commit, so the reviewer could run `cargo`, `node` and +`pnpm exec` to check its findings. + +| Round | Commit | Findings | Main changes made | +| ----- | ------- | -------- | ----------------- | +| 1 | cc05f2f | 13 | Collapse state kept out of raw saves, `innerHTML` reads and cursor paths; collapsed headings found again after updates by a heading key; an edit touching hidden content opens it first; examples added for these (applied by Daniil) | +| 2 | d1e4650 | 14 | Simplified instead of adding rules: the IDE's cursor and scroll never open a section; rule 9 covers the Server's own re-translations; the cursor moves to the heading when its section collapses; the exact Tab order dropped; examples trimmed from 28 to 24 with a test layer each | +| 3 | 6248335 | 11 | With the instructor's advice: CodeMirror's own folding for source files; view-only `
` with an accessible summary (Daniil); tests moved out of the spec and examples cut to 10 (Zhan); heading keys from the Client's current content; a section opens when the cursor enters it, as CodeMirror's folds do; parts that depend on Client bugs say so | +| 4 | 59cabf5 | 18 | Heading kept outside its `
`; TinyMCE's handling of clicks, keys and deletions around `
` described, after checking it with real key presses in headless Chrome; folds recomputed from the collapsed headings; placeholders open their own section; edges of folds and edits other than deletions covered; rules 4, 6, 7, 8 and 9 shortened; one example added | +| 5 | fc58624 | 15, plus 8 simplifications | Folds start at a section's first code, and only the outermost collapsed sections are folded; one rule that the generated elements don't change any key or edit, with the TinyMCE cases that break it; undo, copied content, links, search and new or split headings covered; the cursor defined; example 9 corrected and example 11 extended; rules 2, 5, 8 and 9 shortened | + +#### Last specification review + +Prompting Claude Opus 5.5, extra high effort (Claude Code 2.1.330), with the +prompt below produced the output after it. We reran its scripts and checked the +other findings in headless Chrome, with the installed CodeMirror and TinyMCE, or +by reading the Client's code. Strikethrough marks output that we deemed +incorrect or irrelevant: in Chrome, finding 1's fold draws no placeholder at +all; rule 4 stays so that the rule numbers in all our reviews stay valid; the +instructor asked for rule 7's rationale; the Out of scope bullet also covers a +reload; and `
` in rule 1 is the instructor's advice. + +> Review the spec in client/src/collapsing-headings-spec.md. It relies on +> CodeMirror's own folding and on a view-only \
inside TinyMCE: read +> that code in client/node_modules/@codemirror/language and +> client/node_modules/tinymce, and the Client code that the spec names, and run +> code to check what the spec claims about them. Look for rules, examples and +> Implementation notes that contradict each other, and for behaviour that two +> readers would implement differently. The spec must not overspecify, so also +> say where it can be simplified. Don't edit the spec. Give a numbered list of +> findings, most serious first, each with its location, the problem, and a +> suggested fix. + +I found 15 issues in the spec and 8 places to simplify it. I haven't edited the spec. + +I ran CodeMirror's fold state, decoration spans, height map and search from the installed packages (language 6.13.1, view 6.43.15) in Node. Chrome needed approval I didn't have, and `node_modules` has no DOM library. Findings marked **[run]** were executed; the others come from reading TinyMCE 8.10.1 and the Client, so confirm them in a browser. + +CodeMirror positions use example 3: doc block A is 0–3, the fold is 3–16 and C is 16–17. + +##### Wrong behaviour or contradictions + +1. **[run] Rule 5 (95–97), Implementation (212–213): a fold doesn't hide a whole doc block at its start.** + - **Problem:** The doc block's `block: true` decoration sorts before the fold, so CodeMirror draws the doc block first and folds only what follows. + - With a `//` heading block 0–6, a `///` block 6–8 and a fold of 6–20, CodeMirror draws `[heading] [/// doc]` ~~`…`~~ `[next]`. + - If the section is exactly one doc block, nothing is hidden and no `…` appears. + - This layout is common. `builder/src/main.rs:149–155` is one case, and an approximate scan of the repo's line comments found 55. The Server leaves no gap between such blocks (`processing.rs:1148–1152`). + - **Fix:** Say that a whole doc block at the start of a fold must also be hidden, the same way as a hidden part, and add an example. Starting the fold one position earlier hides it, but then a cursor at the end of the heading's block (6) opens the fold. + +2. **Implementation (197–208), rule 6: TinyMCE has more `
` behaviour than the note lists.** + - **ArrowDown:** On the last line of a `
` that is the body's last child, TinyMCE inserts a paragraph and fires `input` (`tinymce.js:31630–31635`, `39650–39659`). + - In example 1, ArrowDown in p3 edits the document, even with everything open. + - In example 3, ArrowDown in p1 does the same instead of moving to `code1`, which `CodeMirror-integration.mts:978–981` requires. + - **Enter:** In an empty last paragraph, Enter moves that paragraph out of the `
` instead of adding another (`33282–33297`). + - **Outline:** A cursor anywhere in a section sets `data-mce-selected` on the `
` (`13925–13941`). `content.inline.css:949` then draws a 3px outline around the section. + - **Other edits:** "Before such an edit" covers only Backspace and Delete. Cut and typing over a selection also cross the edges. + - **Fix:** State one invariant: "With the generated elements present, every key and edit has the same effect as without them." List these cases as hints. + +3. **Rules 6 and 8, heading key (59–61), example 5: undo isn't covered, and "only" contradicts rule 8.** + - **Problem:** Undo levels are snapshots of the body's HTML, including the generated elements (`24128–24132`). The comparison ignores `open` only in read-only mode (`24156–24163`). + - After a toggle, an arrow key adds an undo level and sets dirty (`28034–28035`, `24246`), so content is sent. Example 5 then fails. + - Undo replaces every node, so a heading's identity is lost. The heading key could restore it, but line 60 allows the key "only" after a Server update. + - **Fix:** Add a bullet: keep the generated elements out of the undo comparison, and rebuild them after Undo and Redo. Let the key be used whenever content is rebuilt. + +4. **[run] Example 9 contradicts rules 7 and 9.** + - **Problem:** `restoreSelection` uses child indices. With the cursor in C at path [4,0], inserting a paragraph above A moves the cursor into p2, which is hidden. Rule 7 then opens A, but the example says A stays collapsed. With the cursor in A or p3 the example holds. I replayed this on a model of the index paths. + - **Also unclear:** "Every section that would hide the cursor" (235) doesn't say whether that is the Client's old cursor or the update's new one. Re-translations carry none (`translation.rs:1242`). + - **Fix:** Say "the update's cursor if it has one, otherwise the Client's". Put the cursor in A in example 9. + +5. **[run] Rule 2 against Implementation (221–224): position 3 has two meanings.** + - **Problem:** It is both the first hidden line and the end of the heading's doc block, where `selectDocBlockEdge` puts the cursor. `foldState` leaves the fold closed there. + - If rule 2's "end of the heading" becomes that position, "the Client must open the section there" reopens the section at once. + - Two readers will also differ on a click beside `…`. + - "The end of a file" makes Select All open the last section. + - **Fix:** Limit the requirement to cursors set by line (`scrollToLine`, go-to-line, search). In source files, have rule 2 leave CodeMirror's selection at the heading block's `from`. + +6. **[run] Rule 5 (97–99) against Implementation (214–220): nested and shared folds.** + - **Problem:** "Outermost section" and "its own section" disagree. + - For [`H1 A`, `H2 B`], `code1`, [`H2 D`], `code2`, [`H1 C`] with A and B collapsed, CodeMirror draws two placeholders, 2–8 and 8–15. The first is B's own fold, but A is the outermost section. + - "`foldState` stores once" is also false within one transaction. Two equal effects are stored twice, and one unfold removes both. + - **Fix:** Fold only the outermost collapsed sections. I checked that this draws one `…`. Each fold then has exactly one section, and most of 214–220 can go. + +7. **[run] Rule 5 (99–100), Out of scope (155–156): the other ways to unfold.** + - **Problem:** The fold gutter and Unfold Code also remove section folds, and the spec doesn't say what happens to the heading. + - Unfold All does nothing if no fold exists, so it can't expand sections that lie inside one doc block. + - Syntax folding doesn't simply "keep working". A collapsed section's line block runs on into the next visible code line. With B collapsed and `code3 {…}` folded by syntax, the default handler for `code3`'s placeholder opens B. + - **Fix:** Write one rule: "When CodeMirror removes a section's fold for any reason, that section expands." Give every placeholder its own fold, including syntax folds. Drop "every section". + +8. **Rules 1, 6 and 7: "the cursor" is undefined in source files, and focusing a summary reports a wrong one.** + - **Problem:** Focusing a summary starts the update timer (`CodeMirror-integration.mts:1332`). `setCodeMirrorPositions` then takes the doc block from `document.activeElement` (2045), which is the summary's block. It takes the path from the selection, which is still in TinyMCE's block or in code. Tabbing through markers therefore moves the IDE's cursor. + - **Fix:** Define the cursor as TinyMCE's if the text cursor is in a doc block, otherwise CodeMirror's main selection head. Say that focusing a summary doesn't change or report it. + +9. **[run] Implementation (228–230): the redraw advice doesn't work and conflicts with rule 2.** + - **Problem:** `DocBlockWidget.eq` ignores collapsed state. An annotated `updateDocBlock` on a loaded block causes no redraw, and neither does an unannotated one on an edited block. `updateDOM` also returns early for a user edit in TinyMCE (516). A real redraw replaces the activated summary, so it loses the focus that rule 2 protects. Line 202 already says to set `open`. + - **Fix:** "Change the shown block in place. Add the generated elements again wherever the Client rebuilds a block's contents." + +10. **Definition of Heading (37–43) against rule 1.** + - **Problem:** Subheadings now sit inside generated `
`, so they aren't direct children and stop being headings. Round 4 removed the sentence that covered this. + - **Fix:** Add "ignoring generated elements". + +11. **Rule 7 (115–120): links.** + - **Problem:** Following a link only scrolls (`followLink` calls `scrollIntoView`), but "a scroll position alone never opens a section". + - **Fix:** Say "Following a link opens every section hiding its target" as a separate sentence. + +12. **Rule 7 (116–117), Implementation (207–208), Out of scope (157–158): search.** + - **Problem:** `searchreplace` marks matches and scrolls on Find and Next. It selects only when the dialog closes (`plugin.js:894–921`, `1048–1053`). A reader who hooks the selection leaves Next showing nothing. Single Replace is an edit too, not just Replace All. "The Client's search covers it" is false in source files, because no Client search reads inactive doc blocks. + - **Fix:** Say "opens the section holding the current match", drop "in Markdown documents", and remove the claim. + +13. **Out of scope (157): the browser can open a `
` itself.** + - **Problem:** By the HTML standard (not run), find-in-page and fragment navigation open a closed `
`. In a source file that shows the doc block's text while the fold stays closed. + - **Fix:** "If the browser opens a generated `
`, the section expands." + +14. **Rule 6: the clipboard.** + - **Problem:** Copy serializes the selection (`35288`), so it can include the generated elements. Pasted ones could then be saved as author-written. Rule 6 covers only content sent to the Server. + - **Fix:** Add copied content to rule 6. + +15. **Unspecified cases.** + - **New headings:** Lines 170–173 require tests for them, but no rule covers them. *Fix:* "Start expanded; if a heading is split, its first part keeps the state." + - **Summary editing:** "View-only" doesn't say whether the cursor can enter the summary, or who handles mousedown. *Fix:* "The summary can't hold the cursor." + - **Read-only Client:** The spec doesn't say whether toggling still works. *Fix:* "Toggling works in a read-only Client." + +##### Where to simplify + +16. ~~**Rule 4:** delete it; rule 1 says it.~~ +17. **Rule 5 (90–95):** delete the restated section boundary; the Section and Document order definitions cover it. +18. **Rule 6, 30–32 and 205–206:** state "never saved" once. +19. **Rule 7:** cut ~~the rationale (111–115) and~~ 121–123, which repeats 236–243. +20. **Rule 9:** cut 145–148 ~~and the first Out of scope bullet~~; "only while the file is open" already says this. +21. **Rule 2 (84–85):** cut the last two sentences; they repeat rules 7 and 8. +22. ~~**Rule 1 (66–69, 73):** keep the behaviour and move the DOM structure to Implementation.~~ +23. **Implementation (231–233):** keep only the last sentence; the rest describes existing code. Also drop "1-based" (56). + +##### Claims that hold + +- **[run]** Only a head strictly inside a fold clears it. +- **[run]** Only deletions clear a touched fold. +- **[run]** A fold mapped through an insert at its start goes stale (3–16 becomes 7–20). +- **[run]** Adjacent collapsed sections share a line block. +- **[run]** Unfolding then folding in one transaction works, in that order. +- **[run]** Examples 3 and 11 draw as stated. +- **By reading:** `basicSetup` includes folding. The click, Enter/Space, Backspace/Delete and raw-save notes match TinyMCE. The Server update paths and the two TODOs match the Client. + +The scripts are in `/private/tmp/ch-review-r5`; run them from the worktree root with `node`. + +### Daniil Chegodayev + +GitHub userid: Daniil-Chegodayev + +#### Contributions + +Applied review fixes with OpenAI Codex, simplified rules 1–4 and 6 after round +2, and rewrote rules 1, 2 and 6 for view-only disclosures and keyboard and +screen-reader access in round 4. + +#### Build and run test + +OpenAI Codex (GPT-6), prompted with "Verify that you can build and run the +project in the current git repo.", verified a complete build and Server startup +on Windows at ef09677 on 1 December 2026. + +* **Environment:** Rust/Cargo 1.100.1 installed with official rustup, Visual C++ + Build Tools 2022 and Windows SDK, cargo-nextest 0.9.152, pnpm 11.25.0, Node + 26.14.0 and the existing npm/npx 11.6.2. Client and extension dependencies + were installed with `pnpm install --frozen-lockfile`; no source or lock files + were changed. The build shell's PATH included the portable Node 26 binary + directory (`%TEMP%\codechat-node-bin`) and `%USERPROFILE%\.cargo\bin`. +* **Build:** `.\bt.ps1 build` completed with exit code **0**. It built the Rust + workspace, exported bindings (13/13 selected tests passed), bundled the + Client and PDF viewer, generated `hashLocations.json`, built and packaged the + VSCode native module and extension, and passed both TypeScript checks. + Compiler/manifest warnings remained, including the unreachable-code warning + at `server/src/webserver.rs:2023`; they did not fail the build. +* **Run:** started `target\debug\codechat-editor-standalone.exe --port 18080 + serve`; `GET http://127.0.0.1:18080/ping` returned HTTP **200** with **pong**. + The test Server was then stopped. This is a startup smoke test; the full test + suite and an interactive UI test were not run. + +The initial missing-Cargo result is superseded by this verified build. A later +attempt with Node 22.14.0 stalled during NAPI packaging because its file-handle +and path stat calls returned different device ids; the same probe with Node +26.14.0 returned matching ids, and the complete build succeeded using Node 26 +with the existing npm. No `bt install` or project-code workaround was needed. + +#### Specification review rounds + +OpenAI Codex reviews of Daniil's changes; finding counts below are local review +counts, separate from Askar's full-spec rounds. + +| Round | Reviewed version | Findings | Main changes made | +| ----- | ---------------- | -------- | ----------------- | +| 1 | fc02540 | 8 | Document order, Rust doc headings, empty sections and sections ending inside one doc block; raw saves, `innerHTML` reads and cursor mapping; heading matching across updates; preserved heading ids; new acceptance examples (applied in d1e4650) | +| Follow-up 1 | d1e4650 | 0 blocking | Text checks only, not a build or feasibility check; Askar's round 2 then found 14 issues | +| 2 (rules 1–4 and 6) | Changes after round 2 | 3, plus 2 consistency issues | Cursor and selection moved to the heading on collapse; exact keyboard navigation promises removed; "left" replaced by "before"; rule 3's cursor-driven expansion removed; rule 6 allows a normal cursor update (applied in bb34d61) | +| Follow-up 2 | bb34d61 | 0 | Wording and cross-references checked | +| 4 (rules 1, 2 and 6) | 0833262 plus Daniil's working changes | 3 | Replace the button contract with an accessible native disclosure; relocate the text cursor before closing so rule 7 does not immediately reopen it; exclude generated disclosure wrappers and state from saved content and remove test instructions from rule 6 | +| Follow-up 4 (same scope) | Round 4 working changes | 0 | Checked against rules 3, 5 and 7, the doc-block focus handler, and MDN's disclosure reference; implementation and runtime accessibility remain unverified | + +#### Last specification review + +OpenAI Codex (GPT-6), 1 December 2026. Review prompt: "Review rules 1, 2 and 6 +against the round 4 advice, round 3 finding 5, the current Client code and the +native details/summary behaviour. Check consistency with rules 3, 5 and 7; +report remaining issues only in Daniil's scope." Earlier local reviews' exact +prompts and model variants were not retained. + +No remaining findings in this scope after the corrections. Rule 1 uses native +view-only disclosures, identifies each summary by its heading, exposes its +state, and requires keyboard access in inactive doc blocks without moving +TinyMCE. It preserves heading semantics rather than assuming that nesting a +heading inside a summary guarantees screen-reader heading navigation. Rule 2 +moves a hidden text selection before closing without stealing summary focus, +consistent with rule 7. Rule 6 removes generated wrappers from outgoing and +saved content while preserving original markup and cursor mapping. Test +instructions were removed from rule 6. No findings were rejected, so no review +items are struck through. This is a specification review, not a claim that the +feature has been implemented or tested with a screen reader. + +References: MDN's [details reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details) +and [summary reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/summary), +and the `focusin` handler in +[CodeMirror-integration.mts](client/src/CodeMirror-integration.mts). + +### Zhan Dzholdybayev + +GitHub userid: zhanapan + +#### Contributions + +Trimmed the examples from 28 to 24 and added the example for the Server's +update after an autosave (round 2), then reduced them to the 10 that show the +main behavior and moved the tests out of the spec (round 4). + +#### Build and run test + +Prompting Gemini 3.5 Flash-Lite (Gemini CLI 0.71.1, no sandbox), started at +0b85d60, with "Verify that you can build and run the project in the current +git repo." reported the following. The first model, gemini-3.8-flash, returned +only quota errors, so I switched models; the free tier's token limit also +interrupted the agent several times. + +* **Build:** the first `./bt build` failed at `export_bindings` ("no such + command: nextest"). After the agent ran `./bt install` (installs tools + globally; I allowed it), the second `./bt build` finished without an Error + line. +* **Tests:** `./bt test` stopped after the `test_vscode_ide_websocket*` tests + failed (190 of 221 not run). I did not investigate. +* **Run:** it started the standalone Server on port 18080, `GET /ping` returned + 200 ("pong"), and it stopped the Server. + +#### Specification review rounds + +Gemini 3.5 Flash-Lite reviewed only the Examples table, against the text of the +rules (not the code). + +| Round | Reviewed version | Findings | Main changes made | +| ----- | ---------------- | -------- | ----------------- | +| 1 | 0b85d60 | 2 (0 correct) | None: one item said no problems were found; the other misquoted example 10 | +| 2 | 0b85d60 | 0 | None: all 10 examples were found consistent with their rules | + +#### Last specification review + +Prompting Gemini 3.5 Flash-Lite with `Read client/src/collapsing-headings-spec.md +in full. Then for each example in the Examples table, say which rule it tests +and whether its expected result follows from that rule and the Definitions. List +only real inconsistencies, each with its location. Do not edit any files.` gave, +for each of the 10 examples, the rule it tests and "Follows correctly: Yes" +(omitted here for length), and then this conclusion. Strikethrough marks output +that we deemed incorrect: the quoted phrase is not in the spec. + +Real Inconsistencies +- Location: client/src/collapsing-headings-spec.md, Examples table. +- Finding: None. All 10 examples follow logically from their respective rules + and definitions without contradiction. ~~(Note: Example 10 contains a minor + typographical agreement error in its description text—"The updates + replaces"—which does not affect logical consistency.)~~ + +Final submission +---------------- + +Not required for this project, which has only a draft submission. diff --git a/toc.md b/toc.md index 809a4395..70396d42 100644 --- a/toc.md +++ b/toc.md @@ -65,6 +65,7 @@ Implementation * Editor * [CodeChatEditorFramework.mts](client/src/CodeChatEditorFramework.mts) * [CodeChatEditor.mts](client/src/CodeChatEditor.mts) + * [Collapsing headings spec](client/src/collapsing-headings-spec.md) * [CodeMirror-integration.mts](client/src/CodeMirror-integration.mts) * [tinymce-config.mts](client/src/tinymce-config.mts) * [graphviz-webcomponent-setup.mjs](client/src/graphviz-webcomponent-setup.mjs)