From cc05f2f7f03ccf9cdc68f13a5064163387d99fe0 Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Sat, 21 Nov 2026 18:09:26 +0500 Subject: [PATCH 01/22] Add draft spec: collapsing headings First draft of the strategy for the "Collapsing headings" project, for the team to review before the LLM review rounds. It defines a heading, its level and its section, the rules for collapsing and expanding in Markdown documents and source files, what is never saved, and ten examples, and points to where the Client would change. Drafted by Claude Opus 5.5 (Claude Code) from a reading of client/src/CodeChatEditor.mts and client/src/CodeMirror-integration.mts. Co-Authored-By: Claude Opus 5.5 (1M context) --- client/src/collapsing-headings-spec.md | 128 +++++++++++++++++++++++++ toc.md | 1 + 2 files changed, 129 insertions(+) create mode 100644 client/src/collapsing-headings-spec.md diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md new file mode 100644 index 00000000..220a4cdd --- /dev/null +++ b/client/src/collapsing-headings-spec.md @@ -0,0 +1,128 @@ +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 an icon beside it that collapses its section: +everything from the heading down to the next heading of the same or a higher +level, including subheadings, doc blocks and code blocks. The icon then changes +to an expand icon, 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. It never changes the document's +text, so nothing about it reaches the Server, the IDE or the saved file. + +Definitions +----------- + +* **Heading:** an `

`–`

` element that 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. +* **Level:** the heading's number: `

` is level 1, the highest. +* **Section:** everything after a heading, 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. + +Rule +---- + +1. **Icon:** each heading shows a button just left of its text: ▾ when its + section is shown, ▸ when collapsed. The button can be reached with the + keyboard and reports its state (`aria-expanded`). It is the only new + control; the heading text stays editable as before. +2. **Collapse:** clicking ▾ hides the heading's section and shows ▸ instead. +3. **Expand:** clicking ▸ shows the section again. A subheading that was + collapsed before stays collapsed, so expanding a section restores it the way + the reader left it. +4. **Markdown documents:** the section is the elements that follow the heading + in the document's contents. +5. **Source files:** a section can span code and doc blocks. It holds the rest + of the heading's doc block, every code and doc block after it, and, in the + doc block holding the heading that ends the section, the content before that + heading. Lines of code in a collapsed section are hidden, not deleted. +6. **Never saved:** collapsing doesn't change the document's text. The icons + and the collapsed state never appear in the HTML the Client turns back into + Markdown, in the updates it sends to the Server, or in the saved file. + Saving a document with sections collapsed gives the same file as saving it + with every section shown. +7. **Shown when needed:** when the cursor or a scroll position from the IDE + lands inside a collapsed section, that section and any collapsed sections + holding it are expanded, so the Client never moves to text the reader can't + see. +8. **Edits:** a section follows its heading as the document changes. If the + heading is deleted or stops being a heading, its section is shown again. + Changing a heading's level changes where its section ends. +9. **Lifetime:** collapsed state lasts while the file is open in the Client. + An update from the IDE keeps the state of the headings that still exist; + opening a file shows every section. + +Out of scope +------------ + +* Remembering collapsed sections after the file is closed or reloaded. +* Commands to collapse or expand every section at once. +* Headings inside lists, block quotes and tables, which aren't headings by the + definition above. +* Folding code by its syntax, which CodeMirror already offers and which stays + as it is. + +Examples +-------- + +`H1 A` is a level-1 heading with text `A`; `p1` is a paragraph; `code1` is a +code block. Each example starts with every section shown. + +| # | Document | Action | Shown afterwards | +| -- | ------------------------------------------------- | ------------------------------- | ----------------------------------------------- | +| 1 | `H1 A`, `p1`, `H2 B`, `p2`, `H1 C`, `p3` | Collapse A | `H1 A`, `H1 C`, `p3` | +| 2 | Same as 1 | Collapse B | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` | +| 3 | Same as 1 | Collapse B, collapse A, expand A | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` (B stays collapsed) | +| 4 | `H2 A`, `p1`, `H3 B`, `p2` | Collapse A | `H2 A` (the section runs to the end) | +| 5 | A list holding `H2 X` | (none) | No icon beside `X` | +| 6 | 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`] | +| 7 | 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`] | +| 8 | Same as 1, A collapsed | Save | The saved file equals the file saved with A shown | +| 9 | Same as 6, A collapsed | The IDE moves the cursor into `code1` | Every section shown; the cursor in `code1` | +| 10 | Same as 1, A collapsed | Delete the heading `A` | `p1`, `H2 B`, `p2`, `H1 C`, `p3` | + +Implementation +-------------- + +* **Markdown documents** ([CodeChatEditor.mts](CodeChatEditor.mts)): the whole + document is one TinyMCE editor. Add each icon as an element TinyMCE leaves + out of its content (`data-mce-bogus="all"`), and hide a section's elements + with a marker TinyMCE also drops when it serializes, so `getContent` and the + saved Markdown don't change (rule 6). Check both against TinyMCE's + serializer before relying on them. +* **Source files** ([CodeMirror-integration.mts](CodeMirror-integration.mts)): + keep the collapsed headings in a `StateField`, as `docBlockField` keeps doc + blocks, so their positions map through edits (rule 8). Hide the lines of a + section with a block `Decoration.replace`, and hide the elements before and + after a heading inside a doc block from `DocBlockWidget.toDOM` and + `updateDOM`, which redraw a doc block. +* **Cursor and scroll** (rule 7): expand the sections around a position before + the Client moves its cursor or scrolls there for the IDE. +* **Tests:** a Client test for each example in + [CodeChatEditor-test.mts](CodeChatEditor-test.mts); the browser tests in + [overall.rs](../../server/tests/overall.rs) are slow, so use them only for + examples 8 and 9, which need the Server. 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) From fc025408135dde6c7c6ef0c1da2144502159a09c Mon Sep 17 00:00:00 2001 From: Daniil-Chegodayev Date: Tue, 24 Nov 2026 19:51:38 +0500 Subject: [PATCH 02/22] Clarify collapse controls, editing and content invariants Co-Authored-By: OpenAI Codex --- client/src/collapsing-headings-spec.md | 54 +++++++++++++++++++------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index 220a4cdd..8ca9997f 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -46,25 +46,49 @@ Definitions Rule ---- -1. **Icon:** each heading shows a button just left of its text: ▾ when its - section is shown, ▸ when collapsed. The button can be reached with the - keyboard and reports its state (`aria-expanded`). It is the only new - control; the heading text stays editable as before. -2. **Collapse:** clicking ▾ hides the heading's section and shows ▸ instead. -3. **Expand:** clicking ▸ shows the section again. A subheading that was - collapsed before stays collapsed, so expanding a section restores it the way - the reader left it. -4. **Markdown documents:** the section is the elements that follow the heading - in the document's contents. +1. **Icon:** each heading always shows a button just left of its text: ▾ + when its section is shown, ▸ when collapsed. Tab and Shift+Tab reach and + leave the button in document order; Enter or Space activates it. The button + has an accessible name identifying its heading and reports its state with + `aria-expanded`. Activating it keeps keyboard focus on the button. It is + the only new control; the heading text stays editable as before. +2. **Collapse:** clicking ▾, or activating it with the keyboard, hides the + heading's section and shows ▸ instead. The heading itself stays visible. + Hidden content cannot receive keyboard focus or be edited while hidden. +3. **Expand:** clicking ▸, or activating it with the keyboard, shows the + section again. A subheading that was collapsed before stays collapsed, so + expanding a section restores it the way the reader left it. +4. **Markdown documents:** the section consists of the elements after the + heading in the document's contents, ending before the next heading of the + same or a higher level, or at the end of the document. Before an edit that + would change hidden content, expand each affected section and any collapsed + sections containing it, then apply the edit with the same result as if that + content had been shown. This includes Backspace or Delete merging across a + collapsed section and replacing or deleting a selection that crosses one. + For example 1 with A collapsed, Backspace at the start of C must reveal A's + section before merging C into p2; selecting from A to C and typing must + reveal the affected hidden content before replacing the selection. The + same edit behavior applies to source files (rule 5). 5. **Source files:** a section can span code and doc blocks. It holds the rest of the heading's doc block, every code and doc block after it, and, in the doc block holding the heading that ends the section, the content before that heading. Lines of code in a collapsed section are hidden, not deleted. -6. **Never saved:** collapsing doesn't change the document's text. The icons - and the collapsed state never appear in the HTML the Client turns back into - Markdown, in the updates it sends to the Server, or in the saved file. - Saving a document with sections collapsed gives the same file as saving it - with every section shown. +6. **Never saved:** collapsing and expanding change only the Client's view. + They do not mark the document as edited or send a document-content update. + Icons and all collapse-only elements, attributes, classes and styles must + be absent from document HTML sent to the Server, from the Markdown the + Server produces from that HTML, and from the saved file. Hidden content + remains present and unchanged in that HTML. This applies both to TinyMCE's + `save({ format: "raw" })` paths and to direct `innerHTML` reads; relying on + TinyMCE's normal serializer alone is insufficient. + Cursor positions sent to the IDE and restored in the Client must refer to + the same document text as with every section shown: collapse controls must + not change child-node paths or text offsets used for cursor mapping. + Verify this for Markdown documents and source-file doc blocks by comparing + outgoing document HTML and the resulting saved file after the same visible + edit with sections collapsed and shown. Also check that collapsing or + expanding alone sends no document content, and that a cursor after a + collapse control maps to the same text in both the Client and the IDE. 7. **Shown when needed:** when the cursor or a scroll position from the IDE lands inside a collapsed section, that section and any collapsed sections holding it are expanded, so the Client never moves to text the reader can't From d1e46503052e424be3c1a34fa88161e95b291cea Mon Sep 17 00:00:00 2001 From: Daniil-Chegodayev Date: Tue, 24 Nov 2026 19:55:11 +0500 Subject: [PATCH 03/22] Resolve full collapsing-headings specification review Review of fc02540 against Client, Server and VSCode extension code: 8 finding groups, all accepted and addressed. 1. Clarify document order, Rust doc headings, empty sections and source sections ending within one doc block. 2. Replace serializer-only implementation guidance with requirements covering raw saves, innerHTML and cursor mapping. 3. Distinguish IDE cursor movement from repeated positions and scroll-only updates. 4. Define heading keys and restoration for incremental and full updates, including duplicate-heading limitations. 5. Preserve independently collapsed descendants when a parent heading is removed or expanded. 6. Preserve existing heading ids and forbid persisted collapse metadata. 7. Replace the save-without-edit example and add missing boundary, edit, lifecycle, keyboard and update cases. 8. Align acceptance-test guidance with actual browser Client tests and end-to-end save/synchronization checks. Follow-up review: no further blocking inconsistencies found. Duplicate-heading identity remains an explicit limitation of the agreed occurrence-based matching rule. Validation: git diff --check, 7 links resolve, 28 examples numbered consecutively, edited prose within 80 columns. Build and runtime tests not run for this specification-only change. Co-Authored-By: OpenAI Codex --- client/src/collapsing-headings-spec.md | 232 +++++++++++++++++-------- 1 file changed, 155 insertions(+), 77 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index 8ca9997f..7d861141 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -21,13 +21,15 @@ Collapsing headings spec ======================== Each heading in a document gets an icon beside it that collapses its section: -everything from the heading down to the next heading of the same or a higher -level, including subheadings, doc blocks and code blocks. The icon then changes -to an expand icon, 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. +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 icon then changes to an expand icon, 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. It never changes the document's -text, so nothing about it reaches the Server, the IDE or the saved file. +Collapsing changes only what the Client shows. Document content sent to the +Server or IDE, and the saved file, contains no collapse controls or state. +Normal cursor and scroll synchronization may still occur. Definitions ----------- @@ -37,42 +39,54 @@ Definitions [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. + 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. -* **Section:** everything after a heading, 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. - -Rule ----- +* **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, exact DOM `textContent` + excluding collapse controls, and its 1-based occurrence among headings with + that same level and text in document order. This key is used only to restore + collapsed state after an IDE content update (rule 9); it is not a saved id. + +Rules +----- 1. **Icon:** each heading always shows a button just left of its text: ▾ - when its section is shown, ▸ when collapsed. Tab and Shift+Tab reach and - leave the button in document order; Enter or Space activates it. The button - has an accessible name identifying its heading and reports its state with - `aria-expanded`. Activating it keeps keyboard focus on the button. It is - the only new control; the heading text stays editable as before. + when its section is shown, ▸ when collapsed. A heading hidden by a collapsed + ancestor and its button are both hidden. Tab and Shift+Tab reach and leave + visible buttons in document order; Enter or Space activates a focused + button. The button has an accessible name identifying its heading and + reports its state with `aria-expanded`. Activating it keeps keyboard focus + on the button. The heading text stays editable as before. An empty section + can be toggled, but no document content is hidden. 2. **Collapse:** clicking ▾, or activating it with the keyboard, hides the heading's section and shows ▸ instead. The heading itself stays visible. - Hidden content cannot receive keyboard focus or be edited while hidden. + Hidden content cannot receive keyboard focus or be edited while hidden; + an edit affecting it first reveals it (rule 8). 3. **Expand:** clicking ▸, or activating it with the keyboard, shows the section again. A subheading that was collapsed before stays collapsed, so - expanding a section restores it the way the reader left it. + expanding a section restores it the way the reader left it. Automatically + expanding a section also preserves collapsed descendants unless they must + open to reveal an edit or cursor target (rules 7 and 8). 4. **Markdown documents:** the section consists of the elements after the heading in the document's contents, ending before the next heading of the - same or a higher level, or at the end of the document. Before an edit that - would change hidden content, expand each affected section and any collapsed - sections containing it, then apply the edit with the same result as if that - content had been shown. This includes Backspace or Delete merging across a - collapsed section and replacing or deleting a selection that crosses one. - For example 1 with A collapsed, Backspace at the start of C must reveal A's - section before merging C into p2; selecting from A to C and typing must - reveal the affected hidden content before replacing the selection. The - same edit behavior applies to source files (rule 5). -5. **Source files:** a section can span code and doc blocks. It holds the rest - of the heading's doc block, every code and doc block after it, and, in the - doc block holding the heading that ends the section, the content before that - heading. Lines of code in a collapsed section are hidden, not deleted. + same or a higher level, or at the end of the document. +5. **Source files:** the same section boundary applies across code and doc + blocks. A section may start and end in the same doc block. Otherwise it + contains the rest of the heading's doc block, all intervening code and doc + blocks, and the content before the ending heading in its doc block. If + there is no ending heading, it contains everything through the end of the + file. Hiding part of a doc block leaves its other content visible. Code in + a collapsed section is hidden, not deleted. 6. **Never saved:** collapsing and expanding change only the Client's view. They do not mark the document as edited or send a document-content update. Icons and all collapse-only elements, attributes, classes and styles must @@ -80,33 +94,60 @@ Rule Server produces from that HTML, and from the saved file. Hidden content remains present and unchanged in that HTML. This applies both to TinyMCE's `save({ format: "raw" })` paths and to direct `innerHTML` reads; relying on - TinyMCE's normal serializer alone is insufficient. + TinyMCE's normal serializer alone is insufficient. Existing heading ids and + other document attributes must be preserved; collapsing adds no saved ids. Cursor positions sent to the IDE and restored in the Client must refer to - the same document text as with every section shown: collapse controls must - not change child-node paths or text offsets used for cursor mapping. + the same document text as with every section shown. Paths and offsets used + for synchronization must describe the document without collapse controls, + even if the displayed DOM contains them. Verify this for Markdown documents and source-file doc blocks by comparing outgoing document HTML and the resulting saved file after the same visible edit with sections collapsed and shown. Also check that collapsing or expanding alone sends no document content, and that a cursor after a collapse control maps to the same text in both the Client and the IDE. -7. **Shown when needed:** when the cursor or a scroll position from the IDE - lands inside a collapsed section, that section and any collapsed sections - holding it are expanded, so the Client never moves to text the reader can't - see. -8. **Edits:** a section follows its heading as the document changes. If the - heading is deleted or stops being a heading, its section is shown again. - Changing a heading's level changes where its section ends. -9. **Lifetime:** collapsed state lasts while the file is open in the Client. - An update from the IDE keeps the state of the headings that still exist; - opening a file shows every section. +7. **Shown when needed:** when the IDE's cursor moves into hidden content, + expand every collapsed section hiding that target before placing the + Client's cursor there. Receiving an unchanged cursor position along with + an IDE update does not itself reopen a section. An IDE scroll position + alone never expands a section: if its target is hidden, scroll to the + heading of the outermost collapsed section hiding it. If an update includes + both a moved cursor and a scroll position, first reveal the cursor target, + then resolve the scroll target using the resulting collapsed state. +8. **Edits:** before a Client edit that would change hidden content, expand + every section needed to reveal the affected content, then apply the edit + with the same result as if that content had been shown. This includes + Backspace or Delete merging across a collapsed section and replacing or + deleting a selection that crosses one, in Markdown and source files. + For example 1 with A collapsed, Backspace at the start of C must reveal A's + section before merging C into p2; selecting from A to C and typing must + reveal the affected hidden content before replacing the selection. + 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 and recomputes visibility. Other collapsed headings retain their own + state, so this does not necessarily reveal every former descendant. +9. **Lifetime:** collapsed state lasts only while the file is open in the + Client. On each IDE content update, retain the keys of collapsed headings + before applying the update and restore collapsed state to the headings with + matching keys afterwards. This applies to both incremental updates and full + content replacements that rebuild the view, before resolving cursor and + scroll targets (rule 7). Discard keys with no match; unmatched new headings + start expanded, though a collapsed ancestor may still hide them. Thus an + IDE rename or level change normally loses that heading's collapsed state. + Occurrence matching is deterministic, but inserting or deleting an + identical heading may transfer the state to another occurrence; tracking + identity across such changes is out of scope. Opening another file, closing + and reopening this file, or reloading the Client starts with all sections + expanded. An automatic full content update of the open file is not a reload. Out of scope ------------ -* Remembering collapsed sections after the file is closed or reloaded. +* Remembering collapsed sections after the file is closed or the Client reloads. * Commands to collapse or expand every section at once. * Headings inside lists, block quotes and tables, which aren't headings by the definition above. +* Tracking heading identity across IDE updates beyond the heading-key rule. * Folding code by its syntax, which CodeMirror already offers and which stays as it is. @@ -114,39 +155,76 @@ Examples -------- `H1 A` is a level-1 heading with text `A`; `p1` is a paragraph; `code1` is a -code block. Each example starts with every section shown. - -| # | Document | Action | Shown afterwards | -| -- | ------------------------------------------------- | ------------------------------- | ----------------------------------------------- | -| 1 | `H1 A`, `p1`, `H2 B`, `p2`, `H1 C`, `p3` | Collapse A | `H1 A`, `H1 C`, `p3` | -| 2 | Same as 1 | Collapse B | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` | -| 3 | Same as 1 | Collapse B, collapse A, expand A | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` (B stays collapsed) | -| 4 | `H2 A`, `p1`, `H3 B`, `p2` | Collapse A | `H2 A` (the section runs to the end) | -| 5 | A list holding `H2 X` | (none) | No icon beside `X` | -| 6 | 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`] | -| 7 | 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`] | -| 8 | Same as 1, A collapsed | Save | The saved file equals the file saved with A shown | -| 9 | Same as 6, A collapsed | The IDE moves the cursor into `code1` | Every section shown; the cursor in `code1` | -| 10 | Same as 1, A collapsed | Delete the heading `A` | `p1`, `H2 B`, `p2`, `H1 C`, `p3` | +code block. Each example starts with every section shown unless its Document +cell specifies otherwise. Results describe visible content and any observable +save or synchronization behavior. IDE content-update examples leave the cursor +outside hidden content unless cursor movement is the action being tested. + +| # | 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 | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` | +| 3 | Same as 1 | Collapse B, collapse A, expand A | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` (B stays collapsed) | +| 4 | `H2 A`, `p1`, `H3 B`, `p2` | Collapse A | `H2 A` (the section runs to the end) | +| 5 | A list holding `H2 X` | (none) | No icon beside `X` | +| 6 | 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`] | +| 7 | 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`] | +| 8 | 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 | +| 9 | Same as 6, A collapsed | The IDE moves the cursor into `code1` | Every section shown; the cursor in `code1` | +| 10 | Same as 1, A collapsed | Delete heading A in the Client | `p1`, `H2 B`, `p2`, `H1 C`, `p3` | +| 11 | Source file: doc block [`H2 A`, `p1`, `H2 B`, `p2`] | Collapse A | Doc block [`H2 A`, `H2 B`, `p2`] | +| 12 | Same as 1, initially clean | Collapse A, then expand A without editing | No document content sent; no dirty state | +| 13 | Same as 1, A collapsed | The IDE inserts a paragraph above A | New paragraph, `H1 A`, `H1 C`, `p3`; A remains collapsed | +| 14 | Same as 1, A collapsed | The IDE renames A to D | `H1 D`, `p1`, `H2 B`, `p2`, `H1 C`, `p3`; D starts expanded | +| 15 | Same as 1, A collapsed | The IDE sends a full content replacement with the same headings and an edit to p3 | `H1 A`, `H1 C`, edited p3; A remains collapsed | +| 16 | Same as 6, A collapsed; IDE cursor outside A's section | The IDE scrolls to `code1`, repeating its unchanged cursor position | A stays collapsed; the Client scrolls to A | +| 17 | Same as 1, A and B collapsed | The IDE moves the cursor into p2 | A and B open before the cursor is placed in p2 | +| 18 | 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 | +| 19 | Same as 1, A collapsed | Select from the start of A to the start of C and type `X` | A opens before replacement; document content equals the same replacement with A shown | +| 20 | Same as 1, A collapsed | Place the Client cursor in C | The position sent to the IDE maps to C, as with A shown | +| 21 | Same as 1, A and B collapsed | Delete heading A in the Client | `p1`, `H2 B`, `H1 C`, `p3`; B stays collapsed | +| 22 | `H2 A`, `p1`, `H2 A`, `p2`, both A headings collapsed | The IDE updates p1 without changing headings | Both A headings remain collapsed, matched by occurrences 1 and 2 | +| 23 | Same as 1, A collapsed | Close and reopen the file | Every section shown | +| 24 | Same as 1 | Tab to A's button, press Space, then Enter | A collapses and expands; focus stays on the button and `aria-expanded` follows its state | +| 25 | `H2 A` at the end of the document | Collapse A | A stays visible, with ▸; no content changes | +| 26 | Source file: doc block rendered from `/// # Examples` and `/// p1`, then `code1`, then doc block rendered from `/// # Next` | Collapse Examples | Doc block [`H1 Examples`], doc block [`H1 Next`] | +| 27 | `H1 A` with an existing id, followed by p1 | Collapse A, edit A's text, wait for autosave | A stays collapsed; the saved heading keeps its id and contains no collapse markup | +| 28 | `H2 A`, `p1`, `H2 B`, `p2`; A collapsed | Change A to level 1 in the Client | A remains collapsed and now also hides B and p2 | Implementation -------------- * **Markdown documents** ([CodeChatEditor.mts](CodeChatEditor.mts)): the whole - document is one TinyMCE editor. Add each icon as an element TinyMCE leaves - out of its content (`data-mce-bogus="all"`), and hide a section's elements - with a marker TinyMCE also drops when it serializes, so `getContent` and the - saved Markdown don't change (rule 6). Check both against TinyMCE's - serializer before relying on them. + document is one TinyMCE editor. Keep fold state separate from document + content. Any display-only DOM additions must be excluded from every content + extraction path, including raw saves and direct `innerHTML` reads (rule 6). + `data-mce-bogus="all"` alone does not establish that these paths are clean. + Keep cursor paths consistent with the content sent to the Server. Display + changes must not create document edits or undo entries; user edits retain + the editor's normal undo behavior. * **Source files** ([CodeMirror-integration.mts](CodeMirror-integration.mts)): - keep the collapsed headings in a `StateField`, as `docBlockField` keeps doc - blocks, so their positions map through edits (rule 8). Hide the lines of a - section with a block `Decoration.replace`, and hide the elements before and - after a heading inside a doc block from `DocBlockWidget.toDOM` and - `updateDOM`, which redraw a doc block. -* **Cursor and scroll** (rule 7): expand the sections around a position before - the Client moves its cursor or scrolls there for the IDE. -* **Tests:** a Client test for each example in - [CodeChatEditor-test.mts](CodeChatEditor-test.mts); the browser tests in - [overall.rs](../../server/tests/overall.rs) are slow, so use them only for - examples 8 and 9, which need the Server. + account for sections spanning code and doc blocks and for boundaries inside + one doc block. A `StateField` can map code positions through Client edits, + but heading boundaries inside doc-block HTML also need tracking. Doc-block + widgets must reflect the fold state when created or updated, including when + an inactive block is moved into or out of TinyMCE. Hidden code must remain + in the underlying document, and fold decorations must coexist with doc-block + replacements and syntax folding without overlapping replacement ranges. +* **IDE updates:** Markdown content is reset with `setContent`; a full source + update destroys and recreates the CodeMirror view, while a source diff uses + transactions. Preserve and restore heading keys across each path (rule 9), + without inserting fold state into the content used as the next diff's base. + Existing heading ids serve cross-references and must remain unchanged. +* **Cursor, scroll and edits:** distinguish cursor movement from a repeated + cursor position in an IDE update, since the IDE also sends its scroll + position. Resolve targets using rule 7 after restoring fold state. Reveal + hidden content before an edit affects it (rule 8), including edits crossing + doc-block boundaries. +* **Tests:** cover every example and rule in Client tests in + [CodeChatEditor-test.mts](CodeChatEditor-test.mts), including raw saves, + inactive doc-block `innerHTML`, nested folds, keyboard focus, and both full + and incremental IDE updates. Repeat save and cursor-mapping checks for both + Markdown and source files. Use the browser integration tests in + [overall.rs](../../server/tests/overall.rs) for end-to-end saving and IDE + synchronization; prefer Client tests for behavior that does not need that + round trip. From 9ee26a9bab918f0fff5e7b6c530c70c0f7bba0ad Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Tue, 24 Nov 2026 20:37:35 +0500 Subject: [PATCH 04/22] Spec: apply round 2 findings to rules 7 and 9 Round 2 of the LLM review (14 findings) showed that rule 7 relied on IDE-to-Client cursor placement the Client doesn't have: Markdown documents ignore the IDE's cursor, and source files get only a line number. Instead of specifying more, rule 7 is simplified: the IDE's cursor and scroll never open a section, and a hidden target scrolls to its heading. Navigation inside the Client (links, search, go-to-line) opens the sections hiding its target. Rule 9 now covers every content update from the Server, including re-translations after a save. The heading key uses the heading's text as the Server sends it, before math is rendered. Undo and redo count as edits under rule 8. Examples 9, 16 and 17 follow the new rule 7. Edits drafted by Claude Opus 5.5 (Claude Code) from the round 2 review and reviewed by Askar Oralkhan. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011e1fmFdDpHsiQY8RfwhXTv --- client/src/collapsing-headings-spec.md | 84 +++++++++++++++----------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index 7d861141..d95fd077 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -52,10 +52,11 @@ Definitions 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, exact DOM `textContent` - excluding collapse controls, and its 1-based occurrence among headings with - that same level and text in document order. This key is used only to restore - collapsed state after an IDE content update (rule 9); it is not a saved id. +* **Heading key:** the tuple of a heading's level, its text in the HTML the + Server sends (before the Client renders any math in it), and its 1-based + occurrence among headings with that same level and text in document order. + This key is used only to restore collapsed state after a content update from + the Server (rule 9); it is not a saved id. Rules ----- @@ -105,35 +106,40 @@ Rules edit with sections collapsed and shown. Also check that collapsing or expanding alone sends no document content, and that a cursor after a collapse control maps to the same text in both the Client and the IDE. -7. **Shown when needed:** when the IDE's cursor moves into hidden content, - expand every collapsed section hiding that target before placing the - Client's cursor there. Receiving an unchanged cursor position along with - an IDE update does not itself reopen a section. An IDE scroll position - alone never expands a section: if its target is hidden, scroll to the - heading of the outermost collapsed section hiding it. If an update includes - both a moved cursor and a scroll position, first reveal the cursor target, - then resolve the scroll target using the resulting collapsed state. +7. **Navigation:** moving to hidden content from inside the Client opens every + collapsed section hiding it. This covers following a link or + cross-reference, and a search or go-to-line that selects hidden content. + The cursor and scroll position the IDE sends never open a section. When + either points into hidden content (a hidden line of code, or a doc block + hidden entirely), the Client scrolls to the heading of the outermost + collapsed section hiding it and leaves its own cursor where it was. A line + in a doc block that is only partly hidden points to that doc block, which + is visible. 8. **Edits:** before a Client edit that would change hidden content, expand every section needed to reveal the affected content, then apply the edit with the same result as if that content had been shown. This includes Backspace or Delete merging across a collapsed section and replacing or - deleting a selection that crosses one, in Markdown and source files. - For example 1 with A collapsed, Backspace at the start of C must reveal A's - section before merging C into p2; selecting from A to C and typing must - reveal the affected hidden content before replacing the selection. + deleting a selection that crosses one, in Markdown and source files. Undo + and redo are edits too. In example 1, with A collapsed, Backspace at the + start of C must reveal A's section before merging C into p2; selecting from + A to C and typing must reveal the affected hidden content before replacing + the selection. 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 and recomputes visibility. Other collapsed headings retain their own state, so this does not necessarily reveal every former descendant. 9. **Lifetime:** collapsed state lasts only while the file is open in the - Client. On each IDE content update, retain the keys of collapsed headings - before applying the update and restore collapsed state to the headings with - matching keys afterwards. This applies to both incremental updates and full - content replacements that rebuild the view, before resolving cursor and - scroll targets (rule 7). Discard keys with no match; unmatched new headings - start expanded, though a collapsed ancestor may still hide them. Thus an - IDE rename or level change normally loses that heading's collapsed state. + 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. This covers edits made in + the IDE and the re-translations the Server sends on its own (after some + saves, or when a cross-referenced target changes). It applies to both + incremental updates and full content replacements that rebuild the view, + before resolving cursor and scroll targets (rule 7). Discard keys with no + match; unmatched new headings start expanded, though a collapsed ancestor + may still hide them. Thus an IDE rename or level change normally loses that + heading's collapsed state. Occurrence matching is deterministic, but inserting or deleting an identical heading may transfer the state to another occurrence; tracking identity across such changes is out of scope. Opening another file, closing @@ -147,7 +153,8 @@ Out of scope * Commands to collapse or expand every section at once. * Headings inside lists, block quotes and tables, which aren't headings by the definition above. -* Tracking heading identity across IDE updates beyond the heading-key rule. +* Tracking heading identity across updates from the Server beyond the + heading-key rule. * Folding code by its syntax, which CodeMirror already offers and which stays as it is. @@ -157,8 +164,9 @@ Examples `H1 A` is a level-1 heading with text `A`; `p1` is a paragraph; `code1` is a code block. Each example starts with every section shown unless its Document cell specifies otherwise. Results describe visible content and any observable -save or synchronization behavior. IDE content-update examples leave the cursor -outside hidden content unless cursor movement is the action being tested. +save or synchronization behavior. Examples of updates from the Server leave +the cursor outside hidden content unless cursor movement is the action being +tested. | # | Document | Action | Expected result | | -- | -- | -- | -- | @@ -170,15 +178,15 @@ outside hidden content unless cursor movement is the action being tested. | 6 | 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`] | | 7 | 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`] | | 8 | 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 | -| 9 | Same as 6, A collapsed | The IDE moves the cursor into `code1` | Every section shown; the cursor in `code1` | +| 9 | Same as 6, A collapsed | The IDE moves the cursor into `code1` | A stays collapsed; the Client scrolls to A and its cursor stays where it was | | 10 | Same as 1, A collapsed | Delete heading A in the Client | `p1`, `H2 B`, `p2`, `H1 C`, `p3` | | 11 | Source file: doc block [`H2 A`, `p1`, `H2 B`, `p2`] | Collapse A | Doc block [`H2 A`, `H2 B`, `p2`] | | 12 | Same as 1, initially clean | Collapse A, then expand A without editing | No document content sent; no dirty state | | 13 | Same as 1, A collapsed | The IDE inserts a paragraph above A | New paragraph, `H1 A`, `H1 C`, `p3`; A remains collapsed | | 14 | Same as 1, A collapsed | The IDE renames A to D | `H1 D`, `p1`, `H2 B`, `p2`, `H1 C`, `p3`; D starts expanded | | 15 | Same as 1, A collapsed | The IDE sends a full content replacement with the same headings and an edit to p3 | `H1 A`, `H1 C`, edited p3; A remains collapsed | -| 16 | Same as 6, A collapsed; IDE cursor outside A's section | The IDE scrolls to `code1`, repeating its unchanged cursor position | A stays collapsed; the Client scrolls to A | -| 17 | Same as 1, A and B collapsed | The IDE moves the cursor into p2 | A and B open before the cursor is placed in p2 | +| 16 | Same as 6, A collapsed; IDE cursor outside A's section | The IDE scrolls to `code1` | A stays collapsed; the Client scrolls to A | +| 17 | Same as 1, A and B collapsed; p3 links to an id in p2 | Follow the link in the Client | A and B open; the Client scrolls to p2 | | 18 | 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 | | 19 | Same as 1, A collapsed | Select from the start of A to the start of C and type `X` | A opens before replacement; document content equals the same replacement with A shown | | 20 | Same as 1, A collapsed | Place the Client cursor in C | The position sent to the IDE maps to C, as with A shown | @@ -210,15 +218,19 @@ Implementation an inactive block is moved into or out of TinyMCE. Hidden code must remain in the underlying document, and fold decorations must coexist with doc-block replacements and syntax folding without overlapping replacement ranges. -* **IDE updates:** Markdown content is reset with `setContent`; a full source - update destroys and recreates the CodeMirror view, while a source diff uses - transactions. Preserve and restore heading keys across each path (rule 9), +* **Updates from the Server:** Markdown content is reset with `setContent`; a + full source update destroys and recreates the CodeMirror view, while a + source diff uses transactions. Re-translations (`is_re_translation`) take + the same paths. Preserve and restore heading keys across each path (rule 9), without inserting fold state into the content used as the next diff's base. Existing heading ids serve cross-references and must remain unchanged. -* **Cursor, scroll and edits:** distinguish cursor movement from a repeated - cursor position in an IDE update, since the IDE also sends its scroll - position. Resolve targets using rule 7 after restoring fold state. Reveal - hidden content before an edit affects it (rule 8), including edits crossing +* **Cursor, scroll and edits:** the IDE sends a line number with every + update; in Markdown documents the Client doesn't follow it yet + (`scrollToLine` is a `TODO`). After restoring fold state, replace a hidden + target with its outermost collapsed heading. In the + Client, `followLink`'s `scrollIntoView()` and CodeMirror's search and + go-to-line must open the sections hiding their target first. Reveal hidden + content before an edit affects it (rule 8), including edits crossing doc-block boundaries. * **Tests:** cover every example and rule in Client tests in [CodeChatEditor-test.mts](CodeChatEditor-test.mts), including raw saves, From bb34d61c393b7c7d13b74c128251c327cf054278 Mon Sep 17 00:00:00 2001 From: Daniil-Chegodayev Date: Tue, 24 Nov 2026 20:43:29 +0500 Subject: [PATCH 05/22] Simplify Daniil rules for round 2 and record review notes --- .../src/collapsing-headings-daniil-reviews.md | 51 ++++++++++++++++ client/src/collapsing-headings-spec.md | 59 ++++++++----------- 2 files changed, 75 insertions(+), 35 deletions(-) create mode 100644 client/src/collapsing-headings-daniil-reviews.md diff --git a/client/src/collapsing-headings-daniil-reviews.md b/client/src/collapsing-headings-daniil-reviews.md new file mode 100644 index 00000000..0e64bb89 --- /dev/null +++ b/client/src/collapsing-headings-daniil-reviews.md @@ -0,0 +1,51 @@ +Codex review notes — Daniil +========================== + +Scope: specification only. No implementation or runtime tests were supplied. + +| Round | Reviewed version | Findings | Changes / result | +| -- | -- | -- | -- | +| Local review 1 | fc02540 | 8 groups | Addressed in d1e4650; see the review below and its commit message. | +| Local follow-up 1 | d1e4650 | 0 further blocking inconsistencies reported | Text checks passed; this was not a build or feasibility check and did not establish that all requirements were supported by existing code. Askar's subsequent review found 14 issues. | +| Local review 2, Daniil scope | Working changes after Askar's round 2 | 3 assigned issues, plus 2 related consistency issues | Defined local cursor/selection relocation; removed exact keyboard navigation promises; replaced left with before; removed rule 3's cursor-driven expansion reference; clarified that cursor relocation may send a cursor update under rule 6. | +| Local follow-up 2, Daniil scope | Current working changes | 0 further findings in rules 1–4 and 6 | Checked wording and cross-references. Full-spec consistency remains pending teammates' assigned changes. | + +The original round 1 with 13 findings and Askar's round 2 with 14 findings +are Askar's reviews, not additional Codex reviews performed in this chat. +Their attachments were not available here. The first Daniil edits were based +on the findings quoted in Askar's email. + +Local review 1 — findings recorded in d1e4650 +------------------------------------------- + +1. Clarify document order, Rust doc headings, empty sections and source sections + ending within one doc block. +2. Replace serializer-only guidance with requirements covering raw saves, + direct innerHTML reads and cursor mapping. +3. Distinguish IDE cursor movement from repeated positions and scroll updates. +4. Define heading matching for incremental and full updates, including the + limitation with duplicate headings. +5. Clarify independently collapsed descendants when a parent is removed. +6. Preserve existing heading ids and exclude persisted collapse metadata. +7. Replace the save-without-edit example and add missing acceptance cases. +8. Align test guidance with browser Client tests and end-to-end checks. + +All eight groups were accepted then; none were rejected. These notes summarize +the review retained in the commit message, rather than a separate verbatim +review transcript. Askar subsequently requested simplification of the result. + +Last local review — Daniil scope +------------------------------- + +Rules 1–4 and 6: no further findings after the current corrections. Keyboard +access is required without promising an exact Tab order. Collapsing relocates +a cursor or selection endpoint from hidden content to the heading. Rule 3 no +longer promises cursor-driven expansion. Rule 6 allows normal cursor updates +while forbidding content updates caused solely by toggling. + +No findings were rejected, so there are no struck-through findings. + +Integration note: the current rule 7, examples and Implementation still reflect +older cursor-expansion behavior. Askar and Zhan own those round 2 changes; +this scoped review does not claim the whole document is ready for submission. +Build and runtime tests were not run for these prose-only changes. diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index d95fd077..a38bcb22 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -61,23 +61,19 @@ Definitions Rules ----- -1. **Icon:** each heading always shows a button just left of its text: ▾ - when its section is shown, ▸ when collapsed. A heading hidden by a collapsed - ancestor and its button are both hidden. Tab and Shift+Tab reach and leave - visible buttons in document order; Enter or Space activates a focused - button. The button has an accessible name identifying its heading and - reports its state with `aria-expanded`. Activating it keeps keyboard focus - on the button. The heading text stays editable as before. An empty section - can be toggled, but no document content is hidden. -2. **Collapse:** clicking ▾, or activating it with the keyboard, hides the - heading's section and shows ▸ instead. The heading itself stays visible. - Hidden content cannot receive keyboard focus or be edited while hidden; - an edit affecting it first reveals it (rule 8). -3. **Expand:** clicking ▸, or activating it with the keyboard, shows the - section again. A subheading that was collapsed before stays collapsed, so - expanding a section restores it the way the reader left it. Automatically - expanding a section also preserves collapsed descendants unless they must - open to reveal an edit or cursor target (rules 7 and 8). +1. **Icon:** each heading shows a button before its text: ▾ when its section + is shown, ▸ when collapsed. The button is always visible unless its heading + is hidden by a collapsed ancestor. It can be reached and activated with the + keyboard and reports its state with `aria-expanded`. The heading text stays + editable as before. +2. **Collapse:** activating ▾ hides the heading's section and shows ▸ instead. + The heading itself stays visible. If the Client's cursor or either end of + its selection is in the section being hidden, move the cursor to the end + of the heading and clear the selection. Hidden content cannot receive + keyboard focus; an edit affecting it first reveals it (rule 8). +3. **Expand:** activating ▸ shows the section again. A subheading that was + collapsed before stays collapsed, unless it must open to reveal an edit + (rule 8). 4. **Markdown documents:** the section consists of the elements after the heading in the document's contents, ending before the next heading of the same or a higher level, or at the end of the document. @@ -88,24 +84,17 @@ Rules there is no ending heading, it contains everything through the end of the file. Hiding part of a doc block leaves its other content visible. Code in a collapsed section is hidden, not deleted. -6. **Never saved:** collapsing and expanding change only the Client's view. - They do not mark the document as edited or send a document-content update. - Icons and all collapse-only elements, attributes, classes and styles must - be absent from document HTML sent to the Server, from the Markdown the - Server produces from that HTML, and from the saved file. Hidden content - remains present and unchanged in that HTML. This applies both to TinyMCE's - `save({ format: "raw" })` paths and to direct `innerHTML` reads; relying on - TinyMCE's normal serializer alone is insufficient. Existing heading ids and - other document attributes must be preserved; collapsing adds no saved ids. - Cursor positions sent to the IDE and restored in the Client must refer to - the same document text as with every section shown. Paths and offsets used - for synchronization must describe the document without collapse controls, - even if the displayed DOM contains them. - Verify this for Markdown documents and source-file doc blocks by comparing - outgoing document HTML and the resulting saved file after the same visible - edit with sections collapsed and shown. Also check that collapsing or - expanding alone sends no document content, and that a cursor after a - collapse control maps to the same text in both the Client and the IDE. +6. **Never saved:** collapsing and expanding do not mark the document as edited + or send document content. All content, including hidden content, is kept; + collapse controls and state are absent from HTML sent to the Server, the + Markdown the Server produces, and the saved file. Existing document + attributes, including heading ids, are preserved. Cursor paths and offsets + describe the document without collapse controls. Moving the cursor under + rule 2 may still send a normal cursor update. + Check both raw TinyMCE saves and direct `innerHTML` reads: after the same + visible edit, outgoing content and the saved file must match those with all + sections shown. Toggling alone sends no document content; a cursor in visible + text maps to the same text with sections collapsed or shown. 7. **Navigation:** moving to hidden content from inside the Client opens every collapsed section hiding it. This covers following a link or cross-reference, and a search or go-to-line that selects hidden content. From 6248335fb1dd8bb547f77c41312a41d8e94c8019 Mon Sep 17 00:00:00 2001 From: zhanapan Date: Thu, 26 Nov 2026 13:18:54 +0500 Subject: [PATCH 06/22] Trim examples, add test layers and new example for Server update --- client/src/collapsing-headings-spec.md | 88 +++++++++++++------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index a38bcb22..57d7f181 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -151,42 +151,40 @@ Examples -------- `H1 A` is a level-1 heading with text `A`; `p1` is a paragraph; `code1` is a -code block. Each example starts with every section shown unless its Document -cell specifies otherwise. Results describe visible content and any observable -save or synchronization behavior. Examples of updates from the Server leave -the cursor outside hidden content unless cursor movement is the action being -tested. - -| # | 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 | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` | -| 3 | Same as 1 | Collapse B, collapse A, expand A | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` (B stays collapsed) | -| 4 | `H2 A`, `p1`, `H3 B`, `p2` | Collapse A | `H2 A` (the section runs to the end) | -| 5 | A list holding `H2 X` | (none) | No icon beside `X` | -| 6 | 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`] | -| 7 | 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`] | -| 8 | 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 | -| 9 | Same as 6, A collapsed | The IDE moves the cursor into `code1` | A stays collapsed; the Client scrolls to A and its cursor stays where it was | -| 10 | Same as 1, A collapsed | Delete heading A in the Client | `p1`, `H2 B`, `p2`, `H1 C`, `p3` | -| 11 | Source file: doc block [`H2 A`, `p1`, `H2 B`, `p2`] | Collapse A | Doc block [`H2 A`, `H2 B`, `p2`] | -| 12 | Same as 1, initially clean | Collapse A, then expand A without editing | No document content sent; no dirty state | -| 13 | Same as 1, A collapsed | The IDE inserts a paragraph above A | New paragraph, `H1 A`, `H1 C`, `p3`; A remains collapsed | -| 14 | Same as 1, A collapsed | The IDE renames A to D | `H1 D`, `p1`, `H2 B`, `p2`, `H1 C`, `p3`; D starts expanded | -| 15 | Same as 1, A collapsed | The IDE sends a full content replacement with the same headings and an edit to p3 | `H1 A`, `H1 C`, edited p3; A remains collapsed | -| 16 | Same as 6, A collapsed; IDE cursor outside A's section | The IDE scrolls to `code1` | A stays collapsed; the Client scrolls to A | -| 17 | Same as 1, A and B collapsed; p3 links to an id in p2 | Follow the link in the Client | A and B open; the Client scrolls to p2 | -| 18 | 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 | -| 19 | Same as 1, A collapsed | Select from the start of A to the start of C and type `X` | A opens before replacement; document content equals the same replacement with A shown | -| 20 | Same as 1, A collapsed | Place the Client cursor in C | The position sent to the IDE maps to C, as with A shown | -| 21 | Same as 1, A and B collapsed | Delete heading A in the Client | `p1`, `H2 B`, `H1 C`, `p3`; B stays collapsed | -| 22 | `H2 A`, `p1`, `H2 A`, `p2`, both A headings collapsed | The IDE updates p1 without changing headings | Both A headings remain collapsed, matched by occurrences 1 and 2 | -| 23 | Same as 1, A collapsed | Close and reopen the file | Every section shown | -| 24 | Same as 1 | Tab to A's button, press Space, then Enter | A collapses and expands; focus stays on the button and `aria-expanded` follows its state | -| 25 | `H2 A` at the end of the document | Collapse A | A stays visible, with ▸; no content changes | -| 26 | Source file: doc block rendered from `/// # Examples` and `/// p1`, then `code1`, then doc block rendered from `/// # Next` | Collapse Examples | Doc block [`H1 Examples`], doc block [`H1 Next`] | -| 27 | `H1 A` with an existing id, followed by p1 | Collapse A, edit A's text, wait for autosave | A stays collapsed; the saved heading keeps its id and contains no collapse markup | -| 28 | `H2 A`, `p1`, `H2 B`, `p2`; A collapsed | Change A to level 1 in the Client | A remains collapsed and now also hides B and p2 | +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. +Examples of updates from the Server leave the cursor outside hidden content +unless cursor movement is the action being tested. The Test column says where +the example is tested (see Tests below). + +| # | Document | Action | Expected result | Test | +| -- | -- | -- | -- | -- | +| 1 | `H1 A`, `p1`, `H2 B`, `p2`, `H1 C`, `p3` | Collapse A | `H1 A`, `H1 C`, `p3` | Client | +| 2 | Same as 1 | Collapse B, collapse A, expand A | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` (B stays collapsed) | Client | +| 3 | `H2 A`, `p1`, `H3 B`, `p2` | Collapse A | `H2 A` (the section runs to the end) | Client | +| 4 | A list holding `H2 X` | (none) | No icon beside `X` | Client | +| 5 | Same as 1 | Tab to A's button, press Space, then Enter | A collapses and expands; focus stays on the button and `aria-expanded` follows its state | Client | +| 6 | 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`] | Client | +| 7 | 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`] | Client | +| 8 | Source file: doc block [`H2 A`, `p1`, `H2 B`, `p2`] | Collapse A | Doc block [`H2 A`, `H2 B`, `p2`] | Client | +| 9 | Same as 1, initially clean | Collapse A, then expand A without editing | No document content sent; no dirty state | Client | +| 10 | 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 | overall.rs | +| 11 | `H1 A` with an existing id, followed by p1 | Collapse A, edit A's text, wait for autosave | A stays collapsed; the saved heading keeps its id and contains no collapse markup | overall.rs | +| 12 | Same as 1, A collapsed | Place the Client cursor in C | The position sent to the IDE maps to C, as with A shown | overall.rs | +| 13 | Same as 6, A collapsed | The IDE moves the cursor into `code1`, or only scrolls to it | A stays collapsed; the Client scrolls to A and its cursor stays where it was | Client | +| 14 | Same as 1, A and B collapsed; p3 links to an id in p2 | Follow the link in the Client | A and B open; the Client scrolls to p2 | Client | +| 15 | 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 | Client | +| 16 | Same as 1, A collapsed | Select from the start of A to the start of C and type `X` | A opens before replacement; document content equals the same replacement with A shown | Client | +| 17 | Same as 1, A and B collapsed | Change A into a paragraph in the Client | Paragraph `A`, `p1`, `H2 B`, `H1 C`, `p3`; B stays collapsed | Client | +| 18 | `H2 A`, `p1`, `H2 B`, `p2`; A collapsed | Change A to level 1 in the Client | A remains collapsed and now also hides B and p2 | Client | +| 19 | Same as 1, A collapsed | The IDE inserts a paragraph above A | New paragraph, `H1 A`, `H1 C`, `p3`; A remains collapsed | Client | +| 20 | Same as 1, A collapsed | The IDE renames A to D | `H1 D`, `p1`, `H2 B`, `p2`, `H1 C`, `p3`; D starts expanded | Client | +| 21 | Same as 6, A collapsed | The IDE edits `code1`, sent once as a full content replacement and once as a diff | A remains collapsed in both cases | Client | +| 22 | `H2 A`, `p1`, `H2 A`, `p2`, both A headings collapsed | The IDE updates p1 without changing headings | Both A headings remain collapsed, matched by occurrences 1 and 2 | Client | +| 23 | Same as 1, A collapsed | Close and reopen the file | Every section shown | overall.rs | +| 24 | 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 | overall.rs | Implementation -------------- @@ -221,11 +219,13 @@ Implementation go-to-line must open the sections hiding their target first. Reveal hidden content before an edit affects it (rule 8), including edits crossing doc-block boundaries. -* **Tests:** cover every example and rule in Client tests in - [CodeChatEditor-test.mts](CodeChatEditor-test.mts), including raw saves, - inactive doc-block `innerHTML`, nested folds, keyboard focus, and both full - and incremental IDE updates. Repeat save and cursor-mapping checks for both - Markdown and source files. Use the browser integration tests in - [overall.rs](../../server/tests/overall.rs) for end-to-end saving and IDE - synchronization; prefer Client tests for behavior that does not need that - round trip. +* **Tests:** every example has one test, in the layer given by its Test + column. Client tests in [CodeChatEditor-test.mts](CodeChatEditor-test.mts) + run only in `test.py?test` and cover the examples that need no Server: + raw saves, inactive doc-block `innerHTML`, nested folds, keyboard focus, and + both full and incremental IDE updates, simulated by calling the Client's + update paths. They have no Markdown fixture yet, so add one next to the + source-file fixture; repeat save checks for both kinds of document. The + examples that need the Server, a saved file or a page reload (10, 11, 12, 23 + and 24) are browser integration tests in + [overall.rs](../../server/tests/overall.rs). From 8d47bd53239d37378b735459dfbd47fcec531ee8 Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Sat, 28 Nov 2026 16:40:19 +0500 Subject: [PATCH 07/22] Add submission.md for the draft submission submission.md follows project_2_submission_template.md: each team member's contribution, build check, review table and last review. Round 3 of the LLM review (11 findings) is the last review in Askar's section. Daniil's Codex review notes move from client/src/collapsing-headings-daniil-reviews.md into his section, so they aren't a separate file in the pull request. Daniil's and Zhan's build checks, and Daniil's Codex model and prompt, are marked for them to fill in. Drafted by Claude Opus 5.5 (Claude Code) and reviewed by Askar Oralkhan. Co-Authored-By: Claude Opus 5.5 --- .../src/collapsing-headings-daniil-reviews.md | 51 ----- submission.md | 178 ++++++++++++++++++ 2 files changed, 178 insertions(+), 51 deletions(-) delete mode 100644 client/src/collapsing-headings-daniil-reviews.md create mode 100644 submission.md diff --git a/client/src/collapsing-headings-daniil-reviews.md b/client/src/collapsing-headings-daniil-reviews.md deleted file mode 100644 index 0e64bb89..00000000 --- a/client/src/collapsing-headings-daniil-reviews.md +++ /dev/null @@ -1,51 +0,0 @@ -Codex review notes — Daniil -========================== - -Scope: specification only. No implementation or runtime tests were supplied. - -| Round | Reviewed version | Findings | Changes / result | -| -- | -- | -- | -- | -| Local review 1 | fc02540 | 8 groups | Addressed in d1e4650; see the review below and its commit message. | -| Local follow-up 1 | d1e4650 | 0 further blocking inconsistencies reported | Text checks passed; this was not a build or feasibility check and did not establish that all requirements were supported by existing code. Askar's subsequent review found 14 issues. | -| Local review 2, Daniil scope | Working changes after Askar's round 2 | 3 assigned issues, plus 2 related consistency issues | Defined local cursor/selection relocation; removed exact keyboard navigation promises; replaced left with before; removed rule 3's cursor-driven expansion reference; clarified that cursor relocation may send a cursor update under rule 6. | -| Local follow-up 2, Daniil scope | Current working changes | 0 further findings in rules 1–4 and 6 | Checked wording and cross-references. Full-spec consistency remains pending teammates' assigned changes. | - -The original round 1 with 13 findings and Askar's round 2 with 14 findings -are Askar's reviews, not additional Codex reviews performed in this chat. -Their attachments were not available here. The first Daniil edits were based -on the findings quoted in Askar's email. - -Local review 1 — findings recorded in d1e4650 -------------------------------------------- - -1. Clarify document order, Rust doc headings, empty sections and source sections - ending within one doc block. -2. Replace serializer-only guidance with requirements covering raw saves, - direct innerHTML reads and cursor mapping. -3. Distinguish IDE cursor movement from repeated positions and scroll updates. -4. Define heading matching for incremental and full updates, including the - limitation with duplicate headings. -5. Clarify independently collapsed descendants when a parent is removed. -6. Preserve existing heading ids and exclude persisted collapse metadata. -7. Replace the save-without-edit example and add missing acceptance cases. -8. Align test guidance with browser Client tests and end-to-end checks. - -All eight groups were accepted then; none were rejected. These notes summarize -the review retained in the commit message, rather than a separate verbatim -review transcript. Askar subsequently requested simplification of the result. - -Last local review — Daniil scope -------------------------------- - -Rules 1–4 and 6: no further findings after the current corrections. Keyboard -access is required without promising an exact Tab order. Collapsing relocates -a cursor or selection endpoint from hidden content to the heading. Rule 3 no -longer promises cursor-driven expansion. Rule 6 allows normal cursor updates -while forbidding content updates caused solely by toggling. - -No findings were rejected, so there are no struck-through findings. - -Integration note: the current rule 7, examples and Implementation still reflect -older cursor-expansion behavior. Askar and Zhan own those round 2 changes; -this scoped review does not claim the whole document is ready for submission. -Build and runtime tests were not run for these prose-only changes. diff --git a/submission.md b/submission.md new file mode 100644 index 00000000..cb9da559 --- /dev/null +++ b/submission.md @@ -0,0 +1,178 @@ +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 three spec review rounds and split +their findings among the team, simplified rules 7 and 9 after round 2, and +wrote this file and the pull request. + +#### Build and run test + +Claude Opus 5.5 (Claude Code), prompted with "Verify that you can build and +run the project in the current git repo.", reported that the project builds +and runs, but not through `./bt build`: + +* The Rust workspace built with `cargo +1.98.0 build --workspace`, the + `export_bindings` tests passed (13 of 13), the Client's esbuild bundles + built, and `tsc -noEmit` reported no errors. +* The standalone server started with + `cargo run -p codechat-editor-standalone -- --port 8765 serve` and served + `/` and `toc.md` with status 200. +* `./bt build` stopped because my default Rust toolchain was broken (since + fixed with `rustup toolchain install stable --force`) and `cargo-nextest` + wasn't installed. It didn't run `./bt install`, because that installs tools + globally and pipes a script from the internet into bash. + +#### 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 | Not applied yet; next: take heading keys from the Client's current content, keep the cursor out of content hidden by a Client edit or a Server update, limit link-following to Markdown until source-file links work, and cover TinyMCE's search and a keyboard route to doc-block buttons | + +#### Last specification review + +Prompting Claude Opus 5.5, extra high effort (Claude Code 2.1.330), with +`Review the spec in client/src/collapsing-headings-spec.md.` produced the +following output. Strikethrough would mark output that we deemed incorrect or +irrelevant; we struck none. + +I found three problems that would cause wrong behaviour if the spec is implemented as written, and some areas the spec doesn't cover. The rules and examples agree with each other: examples 1–3, 6–8, 17 and 18 come out right under the section definition. + +##### Would cause wrong behaviour + +**1. The heading key breaks for headings edited in the Client.** +- **The problem:** the key uses the heading text "in the HTML the Server sends". In example 11 (collapse A, edit its text, autosave), the Server's last HTML still has A's old text. If a re-translation follows, as it does in example 24, the old key won't match the new content and A expands. In source files it's worse: the active doc block's current text is held in TinyMCE, not in `DocBlockWidget.contents`, until autosave. +- **"Text" is ambiguous:** it could mean `textContent` or the inner HTML. The Server writes attributes unquoted (`ref=foo`, `server/src/ide/vscode/tests.rs:2171`); TinyMCE doesn't, so inner HTML won't match between them. +- **Cross-references:** an empty `` inside a heading takes its text from its target. A cross-reference re-translation, one of the cases rule 9 lists, can then change the heading's key. +- **Fix:** take the "before" keys from the Client's current content as it would be sent (no controls, math not rendered). Compare `textContent` with whitespace and ` ` normalised. List the xref case beside the duplicate-heading limitation. + +**2. The cursor can end up in hidden content without anyone collapsing.** Rule 2 only moves the cursor when a section is collapsed. Two other things can hide it: +- **Editing a different heading:** take `H1 A`, p1, `H1 C`, p3 with A collapsed and the cursor in C. Making C an `H2` or a paragraph pulls C and p3 into A's hidden section, cursor included. Example 17 only covers the reverse. +- **Server updates:** Markdown restores the selection as a list of child indexes (`client/src/CodeChatEditor.mts:400-412`, and `client/src/CodeMirror-integration.mts:539-545`). In example 19, a cursor in C (index 4) is put back at index 4, which is now p2, and p2 is hidden. +- **The examples avoid it:** the intro text says Server updates leave the cursor outside hidden content, so this case is never specified. +- **Fix:** a Client edit should never hide what it's editing; expand the section that would swallow it, as rule 8 does. After a Server update, move a hidden cursor to the end of the outermost collapsed heading without opening anything, as rule 7 does. + +**3. Following a link into a collapsed section of a source file depends on an existing bug being fixed.** +- **Why it fails:** `followLink` finds its target with `document.querySelector` (`client/src/CodeChatEditor.mts:734`). CodeMirror only renders content near the viewport, and doesn't render replaced (folded) ranges at all. A collapsed target is never in the page, so the Client can't tell which sections to open. +- **It's already broken:** the same-file link tests are marked `ignore` for this reason (`server/tests/overall/overall_5.rs:1290-1333`). Example 14 is Markdown only, so nothing tests the source-file case. +- **Fix:** either limit the link part of rule 7 to Markdown, with a `TODO:` saying when that limit can go, or require looking up ids in the doc-block contents held in CodeMirror's state. + +##### Not covered by the spec + +**4. TinyMCE's search.** The `searchreplace` plugin is enabled (`client/src/tinymce-config.mts:92`), and it's the only in-editor search in Markdown documents. The Implementation section only names CodeMirror's search and go-to-line. TinyMCE's search needs to open sections, and its Replace All edits hidden content. The spec should also say whether the browser's own find counts. + +**5. Keyboard access.** +- **Tab:** rule 1 deliberately doesn't promise a Tab order, but example 5 says "Tab to A's button". In source files, Tab indents code (`indentWithTab`, `client/src/CodeMirror-integration.mts:1846`) and doc-block contents can't be tabbed to. So there's no stated keyboard route to a doc-block heading's button. +- **Space and Enter:** pressed on a button inside a TinyMCE editor, they also reach TinyMCE's own key handling. Example 5 should check that the content is unchanged and the document isn't marked dirty. +- **Screen readers:** the button's only accessible name is the ▾/▸ symbol. Give it an `aria-label`, and add a collapsed heading to the fixtures used by `overall_a11y.rs`. + +**6. Cases no example covers:** +- **Rule 2's cursor move:** not covered in either document type. +- **Source-file saves and dirty state:** no example covers either, yet the riskiest content-leak paths are source-file only: reading inactive blocks' `innerHTML` (`:826`), TinyMCE→div via `save()` (`:1527`), and div→TinyMCE via `resetContent(contentsDiv.innerHTML)` (`:1547`). The Tests bullet asks for save checks in both document types, but there's no example to give the source-file checks an expected result. +- **New headings:** a heading created in the Client, by changing a paragraph or pasting, getting its button. +- **Undo and redo:** TinyMCE undo replaces the editor's content, so the display-only buttons must be put back afterwards, as after `setContent`. + +**7. The Tests bullet doesn't describe how Client tests run.** +- **Not just `test.py`:** the suite runs on any page loaded with `?test` (`client/src/CodeChatEditor-test.mts:21-24`), once per page load, and then deletes itself. +- **Markdown fixture:** the `test_client` test in `server/tests/overall/overall_1.rs:681-746` loads `test.py` and runs the suite. A Markdown fixture placed beside it won't run until it gets its own test like that. +- **Cheaper layer:** example 12 and the outgoing-HTML part of example 10 check Client-side behaviour (the cursor path and the raw save). They could be Client tests, which AGENTS.md prefers to the slow browser tests. + +##### Nits +- **Paragraph breaks:** the second paragraph in rules 6, 8 and 9 has no blank line before it, so each renders merged into the first. +- **Rule 6:** "Check both raw TinyMCE saves…" is test guidance that repeats the Implementation section. It belongs under Tests. +- **"Every update":** "the IDE sends a line number with every update" isn't accurate. `cursor_position` is optional. +- **Review notes:** `collapsing-headings-daniil-reviews.md` still says rule 7 reflects the older cursor-expansion behaviour, but rule 7 has been rewritten since. + +##### Confirmed correct +- **Heading definition:** `.CodeChat-doc-contents` is the right container in both document types. +- **Rust headings:** `///` is a doc-block delimiter for Rust (`server/src/lexer/supported_languages.rs:372`). +- **Update paths:** the three update paths are as described (`setContent`; destroying and recreating the view; diff transactions). +- **Markdown cursor:** `scrollToLine` really is a `TODO` for Markdown. +- **Gather lists:** they're inserted after their heading, not inside it (`server/src/processing.rs:2329`), so they don't affect heading keys. +- **Line width:** no prose line is longer than 80 characters. + +### Daniil Chegodayev + +GitHub userid: Daniil-Chegodayev + +#### Contributions + +Applied the round 1 findings across the whole spec with OpenAI Codex, then +simplified his rules (1–4 and 6) after round 2: where the cursor goes when a +section collapses, keyboard access without a fixed Tab order, and a shorter +"never saved" rule. + +#### Build and run test + +(Daniil: add a short summary of your LLM's answer to "Verify that you can build +and run the project in the current git repo.", and which LLM you used.) + +#### Specification review rounds + +OpenAI Codex reviews of Daniil's changes, run before and after Askar's round 2: + +| 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 | + +#### Last specification review + +(Daniil: add the Codex model and the prompt you used.) + +Rules 1–4 and 6: no further findings after the current corrections. Keyboard +access is required without promising an exact Tab order. Collapsing relocates +a cursor or selection endpoint from hidden content to the heading. Rule 3 no +longer promises cursor-driven expansion. Rule 6 allows normal cursor updates +while forbidding content updates caused solely by toggling. No findings were +rejected. + +### Zhan Dzholdybayev + +GitHub userid: zhanapan + +#### Contributions + +Trimmed the examples from 28 to 24, added a test layer for each example and +rewrote the test plan to match, and added the example for the Server's update +after an autosave. + +#### Build and run test + +(Zhan: add a short summary of your LLM's answer to "Verify that you can build +and run the project in the current git repo.", and which LLM you used.) + +#### Specification review rounds + +(Zhan: add your review table, or a sentence saying that you didn't run your +own review.) + +#### Last specification review + +(Zhan: add your last review, the prompt and the LLM, if you ran one.) + +Final submission +---------------- + +Not required for this project, which has only a draft submission. From c755d105e933c4873a286fc001d1f5f9a44476e3 Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Sat, 28 Nov 2026 18:04:43 +0500 Subject: [PATCH 08/22] submission: build check runs ./bt build and the Server The earlier build check couldn't use ./bt build (cargo-nextest was missing and the default Rust toolchain was broken). With both fixed, a fresh run of the same prompt built everything with ./bt build, started the standalone Server and got 200 responses from it. Co-Authored-By: Claude Opus 5.5 --- submission.md | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/submission.md b/submission.md index cb9da559..653ace58 100644 --- a/submission.md +++ b/submission.md @@ -21,20 +21,21 @@ wrote this file and the pull request. #### Build and run test -Claude Opus 5.5 (Claude Code), prompted with "Verify that you can build and -run the project in the current git repo.", reported that the project builds -and runs, but not through `./bt build`: - -* The Rust workspace built with `cargo +1.98.0 build --workspace`, the - `export_bindings` tests passed (13 of 13), the Client's esbuild bundles - built, and `tsc -noEmit` reported no errors. -* The standalone server started with - `cargo run -p codechat-editor-standalone -- --port 8765 serve` and served - `/` and `toc.md` with status 200. -* `./bt build` stopped because my default Rust toolchain was broken (since - fixed with `rustup toolchain install stable --force`) and `cargo-nextest` - wasn't installed. It didn't run `./bt install`, because that installs tools - globally and pipes a script from the internet into bash. +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 From 13937fc3eeb03df5fce8cbc577ffdc16502f8a65 Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Sat, 28 Nov 2026 18:40:29 +0500 Subject: [PATCH 09/22] Spec: fold source sections with CodeMirror; round 3 findings 1-4 Following Dr. Jones's advice, source-file sections now use CodeMirror's own folding (foldEffect, foldState) instead of a separate mechanism. Rule 7 follows CodeMirror's behaviour: the cursor never stays in hidden content, so a cursor moving into a collapsed section opens it, while a scroll alone doesn't. The two cases that depend on Client fixes (following the IDE's cursor in Markdown documents, same-file links in source files) are marked as assumed future fixes with TODOs. Round 3 findings: the heading key comes from the Client's current content with whitespace normalised (also CodeRabbit's comment on #165); an edit or Server update that leaves the cursor in hidden content opens it; TinyMCE's search and Replace All are covered; cross-referenced heading text is a stated limitation. Example 13 follows the new rule 7. Edits drafted by Claude Opus 5.5 (Claude Code), with CodeMirror's fold behaviour checked in @codemirror/language 6.13.1, and reviewed by Askar Oralkhan. Co-Authored-By: Claude Opus 5.5 --- client/src/collapsing-headings-spec.md | 97 ++++++++++++++++---------- 1 file changed, 61 insertions(+), 36 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index 57d7f181..05db97af 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -52,11 +52,13 @@ Definitions 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 in the HTML the - Server sends (before the Client renders any math in it), and its 1-based +* **Heading key:** the tuple of a heading's level, its text, and its 1-based occurrence among headings with that same level and text in document order. - This key is used only to restore collapsed state after a content update from - the Server (rule 9); it is not a saved id. + The text is the heading's `textContent` in the Client's current content, as + the Client would send it to the Server (no collapse controls, math not yet + rendered), with each run of whitespace, including non-breaking spaces, + collapsed to one space. This key is used only to restore collapsed state + after a content update from the Server (rule 9); it is not a saved id. Rules ----- @@ -83,7 +85,10 @@ Rules blocks, and the content before the ending heading in its doc block. If there is no ending heading, it contains everything through the end of the file. Hiding part of a doc block leaves its other content visible. Code in - a collapsed section is hidden, not deleted. + a collapsed section is hidden, not deleted. The code and whole doc blocks + in a section are folded with CodeMirror's own folding, so they show as + CodeMirror's fold placeholder (…). Clicking the placeholder, or a CodeMirror + unfold command such as Unfold All, expands the section like ▸. 6. **Never saved:** collapsing and expanding do not mark the document as edited or send document content. All content, including hidden content, is kept; collapse controls and state are absent from HTML sent to the Server, the @@ -95,15 +100,20 @@ Rules visible edit, outgoing content and the saved file must match those with all sections shown. Toggling alone sends no document content; a cursor in visible text maps to the same text with sections collapsed or shown. -7. **Navigation:** moving to hidden content from inside the Client opens every - collapsed section hiding it. This covers following a link or - cross-reference, and a search or go-to-line that selects hidden content. - The cursor and scroll position the IDE sends never open a section. When - either points into hidden content (a hidden line of code, or a doc block - hidden entirely), the Client scrolls to the heading of the outermost - collapsed section hiding it and leaves its own cursor where it was. A line - in a doc block that is only partly hidden points to that doc block, which - is visible. +7. **Cursor in hidden content:** the cursor never stays in hidden content. + When it moves there, every collapsed section hiding it opens, as + CodeMirror's folding already does for code. This covers the cursor the IDE + sends, a search or go-to-line that selects hidden content (including + TinyMCE's search in Markdown documents), following a link or + cross-reference, and a Client edit or Server update that leaves the cursor + in a collapsed section, such as changing a heading's level so that a + collapsed section now holds the cursor. A line in a doc block that is only + partly hidden 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, and this spec assumes + they will be made: in Markdown documents the Client doesn't yet follow the + IDE's cursor (`scrollToLine` is a `TODO`), and same-file links don't yet + work in source files (their tests in `overall_5.rs` are ignored). 8. **Edits:** before a Client edit that would change hidden content, expand every section needed to reveal the affected content, then apply the edit with the same result as if that content had been shown. This includes @@ -130,8 +140,10 @@ Rules may still hide them. Thus an IDE rename or level change normally loses that heading's collapsed state. Occurrence matching is deterministic, but inserting or deleting an - identical heading may transfer the state to another occurrence; tracking - identity across such changes is out of scope. Opening another file, closing + identical heading may transfer the state to another occurrence, and a + heading whose text comes from a cross-reference gets a new key when its + target's text changes; tracking identity across such changes is out of + scope. Opening another file, closing and reopening this file, or reloading the Client starts with all sections expanded. An automatic full content update of the open file is not a reload. @@ -144,8 +156,10 @@ Out of scope definition above. * Tracking heading identity across updates from the Server beyond the heading-key rule. -* Folding code by its syntax, which CodeMirror already offers and which stays - as it is. +* Changing CodeMirror's folding by syntax, which keeps working alongside the + folds that collapsed sections add. +* Finding hidden text with the browser's own find; the Client's search covers + it (rule 7). Examples -------- @@ -173,7 +187,7 @@ the example is tested (see Tests below). | 10 | 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 | overall.rs | | 11 | `H1 A` with an existing id, followed by p1 | Collapse A, edit A's text, wait for autosave | A stays collapsed; the saved heading keeps its id and contains no collapse markup | overall.rs | | 12 | Same as 1, A collapsed | Place the Client cursor in C | The position sent to the IDE maps to C, as with A shown | overall.rs | -| 13 | Same as 6, A collapsed | The IDE moves the cursor into `code1`, or only scrolls to it | A stays collapsed; the Client scrolls to A and its cursor stays where it was | Client | +| 13 | Same as 6, A collapsed | The IDE moves the cursor into `code1` | A opens; the cursor is in `code1` | Client | | 14 | Same as 1, A and B collapsed; p3 links to an id in p2 | Follow the link in the Client | A and B open; the Client scrolls to p2 | Client | | 15 | 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 | Client | | 16 | Same as 1, A collapsed | Select from the start of A to the start of C and type `X` | A opens before replacement; document content equals the same replacement with A shown | Client | @@ -198,27 +212,38 @@ Implementation changes must not create document edits or undo entries; user edits retain the editor's normal undo behavior. * **Source files** ([CodeMirror-integration.mts](CodeMirror-integration.mts)): - account for sections spanning code and doc blocks and for boundaries inside - one doc block. A `StateField` can map code positions through Client edits, - but heading boundaries inside doc-block HTML also need tracking. Doc-block - widgets must reflect the fold state when created or updated, including when - an inactive block is moved into or out of TinyMCE. Hidden code must remain - in the underlying document, and fold decorations must coexist with doc-block - replacements and syntax folding without overlapping replacement ranges. + fold the code and whole doc blocks of a section with the folding in + `@codemirror/language`, which `basicSetup` already includes. `foldEffect` + and `unfoldEffect` add and remove a fold, and `foldState` maps it through + edits. `foldState` also clears a fold that a deletion touches or that the + selection head moves into (`clearTouchedFolds`), which gives rules 7 and 8 + for code. A fold starts and ends at doc-block boundaries, so it never + partly overlaps a doc block's own `Decoration.replace` widget; the parts of + the first and last doc blocks that belong to the section are hidden inside + those blocks (rule 1). `DocBlockWidget.eq` must compare that state, so that + `toDOM` and `updateDOM` redraw the block, including when TinyMCE moves into + or out of it. See the CodeMirror + [folding reference](https://codemirror.net/docs/ref/#language.foldEffect). * **Updates from the Server:** Markdown content is reset with `setContent`; a full source update destroys and recreates the CodeMirror view, while a source diff uses transactions. Re-translations (`is_re_translation`) take - the same paths. Preserve and restore heading keys across each path (rule 9), - without inserting fold state into the content used as the next diff's base. + the same paths. A diff maps CodeMirror's folds through its changes; a full + update recreates the view and its `foldState`. Restore collapsed state by + heading key after each path (rule 9), without inserting fold state into the + content used as the next diff's base. Existing heading ids serve cross-references and must remain unchanged. -* **Cursor, scroll and edits:** the IDE sends a line number with every - update; in Markdown documents the Client doesn't follow it yet - (`scrollToLine` is a `TODO`). After restoring fold state, replace a hidden - target with its outermost collapsed heading. In the - Client, `followLink`'s `scrollIntoView()` and CodeMirror's search and - go-to-line must open the sections hiding their target first. Reveal hidden - content before an edit affects it (rule 8), including edits crossing - doc-block boundaries. +* **Cursor, scroll and edits:** in source files, setting CodeMirror's + selection to the IDE's cursor line opens the folds around it (rule 7). + 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 + test 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` and TinyMCE's + `searchreplace` must open the sections hiding their target, and its Replace + All is an edit (rule 8). Reveal hidden content before an edit affects it + (rule 8), including edits crossing doc-block boundaries. * **Tests:** every example has one test, in the layer given by its Test column. Client tests in [CodeChatEditor-test.mts](CodeChatEditor-test.mts) run only in `test.py?test` and cover the examples that need no Server: From 7a2552160c87d166436801669bfd31056216fb7b Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Sat, 28 Nov 2026 23:01:07 +0500 Subject: [PATCH 10/22] Spec: document why a cursor in a collapsed section opens it Dr. Jones agreed that opening a collapsed section when the cursor moves into it is a reasonable design decision and asked us to document it with its rationale. Rule 7 now names the alternative (keeping the section collapsed and moving the cursor past the fold) and the reason for the choice: it matches CodeMirror's fold behaviour, so collapsed sections and code folds behave the same across the Client's UI. Co-Authored-By: Claude Opus 5.5 --- client/src/collapsing-headings-spec.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index 05db97af..b681604a 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -100,16 +100,18 @@ Rules visible edit, outgoing content and the saved file must match those with all sections shown. Toggling alone sends no document content; a cursor in visible text maps to the same text with sections collapsed or shown. -7. **Cursor in hidden content:** the cursor never stays in hidden content. - When it moves there, every collapsed section hiding it opens, as - CodeMirror's folding already does for code. This covers the cursor the IDE - sends, a search or go-to-line that selects hidden content (including - TinyMCE's search in Markdown documents), following a link or - cross-reference, and a Client edit or Server update that leaves the cursor - in a collapsed section, such as changing a heading's level so that a - collapsed section now holds the cursor. A line in a doc block that is only - partly hidden points to that doc block, which is visible, so it opens - nothing. A scroll position alone never opens a section. +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, a search or go-to-line + that selects hidden content (including TinyMCE's search in Markdown + documents), following a link or cross-reference, and a Client edit or Server + update that leaves the cursor in a collapsed section, such as changing a + heading's level so that a collapsed section now holds the cursor. A line in a + doc block that is only partly hidden 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, and this spec assumes they will be made: in Markdown documents the Client doesn't yet follow the IDE's cursor (`scrollToLine` is a `TODO`), and same-file links don't yet From 30ef1ff96ed4df85c17bbe7e36252d340700a406 Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Sat, 28 Nov 2026 23:13:29 +0500 Subject: [PATCH 11/22] Spec: open a restored section that still hides the cursor CodeRabbit noted on #165 that foldState clears a fold only when a transaction sets the selection, so restoring collapsed state after a Server update could leave the cursor in a collapsed section, against rule 7. The Implementation section now says to unfold that section in the same transaction, and to leave its
open in Markdown documents. Co-Authored-By: Claude Opus 5.5 --- client/src/collapsing-headings-spec.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index b681604a..13fc1fbf 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -232,7 +232,11 @@ Implementation the same paths. A diff maps CodeMirror's folds through its changes; a full update recreates the view and its `foldState`. Restore collapsed state by heading key after each path (rule 9), without inserting fold state into the - content used as the next diff's base. + content used as the next diff's base. Then open any restored section that + still hides the cursor (rule 7): `foldState` clears a fold only when a + transaction sets the selection, so include `unfoldEffect` for that fold in + the same transaction; in Markdown documents, leave that section's + `
` open. Existing heading ids serve cross-references and must remain unchanged. * **Cursor, scroll and edits:** in source files, setting CodeMirror's selection to the IDE's cursor line opens the folds around it (rule 7). From 0b85d6088c3c4667c2f876293ef4b839375d1c7d Mon Sep 17 00:00:00 2001 From: zhanapan Date: Mon, 30 Nov 2026 15:25:04 +0500 Subject: [PATCH 12/22] Spec: move tests out of the examples, keep 10 main examples --- client/src/collapsing-headings-spec.md | 60 +++++++++----------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index 13fc1fbf..0f47840c 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -171,36 +171,25 @@ 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. -Examples of updates from the Server leave the cursor outside hidden content -unless cursor movement is the action being tested. The Test column says where -the example is tested (see Tests below). - -| # | Document | Action | Expected result | Test | -| -- | -- | -- | -- | -- | -| 1 | `H1 A`, `p1`, `H2 B`, `p2`, `H1 C`, `p3` | Collapse A | `H1 A`, `H1 C`, `p3` | Client | -| 2 | Same as 1 | Collapse B, collapse A, expand A | `H1 A`, `p1`, `H2 B`, `H1 C`, `p3` (B stays collapsed) | Client | -| 3 | `H2 A`, `p1`, `H3 B`, `p2` | Collapse A | `H2 A` (the section runs to the end) | Client | -| 4 | A list holding `H2 X` | (none) | No icon beside `X` | Client | -| 5 | Same as 1 | Tab to A's button, press Space, then Enter | A collapses and expands; focus stays on the button and `aria-expanded` follows its state | Client | -| 6 | 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`] | Client | -| 7 | 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`] | Client | -| 8 | Source file: doc block [`H2 A`, `p1`, `H2 B`, `p2`] | Collapse A | Doc block [`H2 A`, `H2 B`, `p2`] | Client | -| 9 | Same as 1, initially clean | Collapse A, then expand A without editing | No document content sent; no dirty state | Client | -| 10 | 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 | overall.rs | -| 11 | `H1 A` with an existing id, followed by p1 | Collapse A, edit A's text, wait for autosave | A stays collapsed; the saved heading keeps its id and contains no collapse markup | overall.rs | -| 12 | Same as 1, A collapsed | Place the Client cursor in C | The position sent to the IDE maps to C, as with A shown | overall.rs | -| 13 | Same as 6, A collapsed | The IDE moves the cursor into `code1` | A opens; the cursor is in `code1` | Client | -| 14 | Same as 1, A and B collapsed; p3 links to an id in p2 | Follow the link in the Client | A and B open; the Client scrolls to p2 | Client | -| 15 | 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 | Client | -| 16 | Same as 1, A collapsed | Select from the start of A to the start of C and type `X` | A opens before replacement; document content equals the same replacement with A shown | Client | -| 17 | Same as 1, A and B collapsed | Change A into a paragraph in the Client | Paragraph `A`, `p1`, `H2 B`, `H1 C`, `p3`; B stays collapsed | Client | -| 18 | `H2 A`, `p1`, `H2 B`, `p2`; A collapsed | Change A to level 1 in the Client | A remains collapsed and now also hides B and p2 | Client | -| 19 | Same as 1, A collapsed | The IDE inserts a paragraph above A | New paragraph, `H1 A`, `H1 C`, `p3`; A remains collapsed | Client | -| 20 | Same as 1, A collapsed | The IDE renames A to D | `H1 D`, `p1`, `H2 B`, `p2`, `H1 C`, `p3`; D starts expanded | Client | -| 21 | Same as 6, A collapsed | The IDE edits `code1`, sent once as a full content replacement and once as a diff | A remains collapsed in both cases | Client | -| 22 | `H2 A`, `p1`, `H2 A`, `p2`, both A headings collapsed | The IDE updates p1 without changing headings | Both A headings remain collapsed, matched by occurrences 1 and 2 | Client | -| 23 | Same as 1, A collapsed | Close and reopen the file | Every section shown | overall.rs | -| 24 | 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 | overall.rs | + +These examples show the main behavior. Unusual cases are covered by tests +instead of being listed here; for example, the cursor move in rule 2, saves and +dirty state in source files, new headings, undo and redo, and TinyMCE's search. +See the Client tests in [CodeChatEditor-test.mts](CodeChatEditor-test.mts) and +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 | 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 | Implementation -------------- @@ -250,13 +239,4 @@ Implementation `searchreplace` must open the sections hiding their target, and its Replace All is an edit (rule 8). Reveal hidden content before an edit affects it (rule 8), including edits crossing doc-block boundaries. -* **Tests:** every example has one test, in the layer given by its Test - column. Client tests in [CodeChatEditor-test.mts](CodeChatEditor-test.mts) - run only in `test.py?test` and cover the examples that need no Server: - raw saves, inactive doc-block `innerHTML`, nested folds, keyboard focus, and - both full and incremental IDE updates, simulated by calling the Client's - update paths. They have no Markdown fixture yet, so add one next to the - source-file fixture; repeat save checks for both kinds of document. The - examples that need the Server, a saved file or a page reload (10, 11, 12, 23 - and 24) are browser integration tests in - [overall.rs](../../server/tests/overall.rs). + From 0833262d60d4f39b502af833e72ad63d399f4f47 Mon Sep 17 00:00:00 2001 From: zhanapan Date: Tue, 1 Dec 2026 10:40:05 +0500 Subject: [PATCH 13/22] submission: build check and review for Zhan --- submission.md | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/submission.md b/submission.md index 653ace58..82f40082 100644 --- a/submission.md +++ b/submission.md @@ -155,23 +155,53 @@ GitHub userid: zhanapan #### Contributions -Trimmed the examples from 28 to 24, added a test layer for each example and -rewrote the test plan to match, and added the example for the Server's update -after an autosave. +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 -(Zhan: add a short summary of your LLM's answer to "Verify that you can build -and run the project in the current git repo.", and which LLM you used.) +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` . +* **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 -(Zhan: add your review table, or a sentence saying that you didn't run your -own review.) +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 -(Zhan: add your last review, the prompt and the LLM, if you ran one.) +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 ---------------- From 8b9e51e3dd0551b6c4e946949b772f1492e26625 Mon Sep 17 00:00:00 2001 From: Daniil-Chegodayev Date: Tue, 1 Dec 2026 19:18:45 +0500 Subject: [PATCH 14/22] Revise Daniil rules for view-only disclosures and accessibility --- client/src/collapsing-headings-spec.md | 50 ++++++++++++++----------- submission.md | 51 ++++++++++++++++++-------- 2 files changed, 65 insertions(+), 36 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index 0f47840c..4752000b 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -63,16 +63,26 @@ Definitions Rules ----- -1. **Icon:** each heading shows a button before its text: ▾ when its section - is shown, ▸ when collapsed. The button is always visible unless its heading - is hidden by a collapsed ancestor. It can be reached and activated with the - keyboard and reports its state with `aria-expanded`. The heading text stays - editable as before. -2. **Collapse:** activating ▾ hides the heading's section and shows ▸ instead. - The heading itself stays visible. If the Client's cursor or either end of - its selection is in the section being hidden, move the cursor to the end - of the heading and clear the selection. Hidden content cannot receive - keyboard focus; an edit affecting it first reveals it (rule 8). +1. **Disclosure:** use view-only `
` and `` elements for + Markdown content and the parts of a section inside doc blocks; code and + whole doc blocks use CodeMirror's folding (rule 5). The summary replaces + the button and shows ▾ when open and ▸ when closed, before the heading + text. These wrappers do not change which headings qualify or their section + boundaries. + The heading stays editable and retains its heading level for screen readers. + Visible summaries, including those in inactive doc blocks, are reachable + and can be left through page keyboard navigation without a mouse. Enter or + Space on a focused summary toggles it without editing the document. Its + accessible name identifies the heading, and its expanded or collapsed + state is exposed through the native disclosure semantics. Focusing a + doc-block summary leaves TinyMCE in its current block. +2. **Collapse:** closing the disclosure hides the heading's section and shows + the collapsed marker ▸. The heading and its summary stay visible. Before + closing, if the Client's text cursor or either end of its selection is in + the section being hidden, move that cursor to the end of the heading and + clear the selection, without taking focus from the activating summary. + This avoids reopening the section under rule 7. Hidden content cannot + receive keyboard focus; an edit affecting it first reveals it (rule 8). 3. **Expand:** activating ▸ shows the section again. A subheading that was collapsed before stays collapsed, unless it must open to reveal an edit (rule 8). @@ -89,17 +99,15 @@ Rules in a section are folded with CodeMirror's own folding, so they show as CodeMirror's fold placeholder (…). Clicking the placeholder, or a CodeMirror unfold command such as Unfold All, expands the section like ▸. -6. **Never saved:** collapsing and expanding do not mark the document as edited - or send document content. All content, including hidden content, is kept; - collapse controls and state are absent from HTML sent to the Server, the - Markdown the Server produces, and the saved file. Existing document - attributes, including heading ids, are preserved. Cursor paths and offsets - describe the document without collapse controls. Moving the cursor under - rule 2 may still send a normal cursor update. - Check both raw TinyMCE saves and direct `innerHTML` reads: after the same - visible edit, outgoing content and the saved file must match those with all - sections shown. Toggling alone sends no document content; a cursor in visible - text maps to the same text with sections collapsed or shown. +6. **Never saved:** collapsing and expanding change only the Client's view; + they do not mark the document as edited or send document content. All + content, including hidden content, is kept. The generated `
` and + `` wrappers, their open state, and other collapse-only markup are + absent from content sent to the Server, the Markdown it produces, and the + saved file. Original document markup and attributes, including heading ids + and any author-written disclosure elements, are preserved. Cursor paths + and offsets describe the document without the generated controls and + wrappers. 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 diff --git a/submission.md b/submission.md index 82f40082..b3eebfe5 100644 --- a/submission.md +++ b/submission.md @@ -117,19 +117,24 @@ GitHub userid: Daniil-Chegodayev #### Contributions -Applied the round 1 findings across the whole spec with OpenAI Codex, then -simplified his rules (1–4 and 6) after round 2: where the cursor goes when a -section collapses, keyboard access without a fixed Tab order, and a shorter -"never saved" rule. +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 -(Daniil: add a short summary of your LLM's answer to "Verify that you can build -and run the project in the current git repo.", and which LLM you used.) +OpenAI Codex (GPT-6) checked "Verify that you can build and run the project in +the current git repo." on Windows at 0833262 on 1 December 2026: running +`.\bt.ps1 build` stopped at the wrapper's `cargo run` command because `cargo` +was not found in PATH (nor at the usual user `.cargo/bin/cargo.exe` location). +The wrapper returned exit code 0 despite that error; this is not a successful +build. The Server could not be built or started by this check, so neither the +build nor run is verified. No global tools were installed or `bt install` run. #### Specification review rounds -OpenAI Codex reviews of Daniil's changes, run before and after Askar's round 2: +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 | | ----- | ---------------- | -------- | ----------------- | @@ -137,17 +142,33 @@ OpenAI Codex reviews of Daniil's changes, run before and after Askar's round 2: | 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 -(Daniil: add the Codex model and the prompt you used.) - -Rules 1–4 and 6: no further findings after the current corrections. Keyboard -access is required without promising an exact Tab order. Collapsing relocates -a cursor or selection endpoint from hidden content to the heading. Rule 3 no -longer promises cursor-driven expansion. Rule 6 allows normal cursor updates -while forbidding content updates caused solely by toggling. No findings were -rejected. +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 From 59cabf5ac318a066317dfbdd85c6aed7339018c6 Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Tue, 1 Dec 2026 19:25:07 +0500 Subject: [PATCH 15/22] Spec: name required tests, show fold placeholders, open doc-block sections Say that the implementation must add the tests instead of claiming they exist, include CodeMirror's fold placeholder in examples 3 and 4, cover a cursor hidden inside a doc block after a Server update, and describe the marker instead of an icon. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011e1fmFdDpHsiQY8RfwhXTv --- client/src/collapsing-headings-spec.md | 44 ++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index 4752000b..cca9c5a4 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -20,12 +20,12 @@ CodeChat Editor. If not, see Collapsing headings spec ======================== -Each heading in a document gets an icon beside it 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 icon then changes to an expand icon, 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. +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. Document content sent to the Server or IDE, and the saved file, contains no collapse controls or state. @@ -178,20 +178,22 @@ Examples 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. - -These examples show the main behavior. Unusual cases are covered by tests -instead of being listed here; for example, the cursor move in rule 2, saves and -dirty state in source files, new headings, undo and redo, and TinyMCE's search. -See the Client tests in [CodeChatEditor-test.mts](CodeChatEditor-test.mts) and -the browser tests in [overall](../../server/tests/overall/). - +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`] | +| 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` | @@ -230,10 +232,12 @@ Implementation update recreates the view and its `foldState`. Restore collapsed state by heading key after each path (rule 9), without inserting fold state into the content used as the next diff's base. Then open any restored section that - still hides the cursor (rule 7): `foldState` clears a fold only when a - transaction sets the selection, so include `unfoldEffect` for that fold in - the same transaction; in Markdown documents, leave that section's - `
` open. + still hides the cursor (rule 7), and only those sections. `foldState` clears + a fold only when a transaction sets the selection, so include `unfoldEffect` + for that section's fold in the same transaction. A cursor hidden inside a + doc block has no fold over it: clear the heading's collapsed state, so that + `DocBlockWidget.eq` returns false and the block is redrawn. In Markdown + documents, leave that section's `
` open. Existing heading ids serve cross-references and must remain unchanged. * **Cursor, scroll and edits:** in source files, setting CodeMirror's selection to the IDE's cursor line opens the folds around it (rule 7). From 1e5382929c8add6cca88b536617b0f6b864379b4 Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Tue, 1 Dec 2026 19:36:03 +0500 Subject: [PATCH 16/22] Spec: apply review round 4 Keep the heading outside its details element, describe what TinyMCE and CodeMirror's folding need from the Client (checked by running both), recompute folds from the collapsed headings, cover the edges of folds and edits other than deletions, and shorten rules 4 and 6 to 9. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011e1fmFdDpHsiQY8RfwhXTv --- client/src/collapsing-headings-spec.md | 189 ++++++++++++------------- 1 file changed, 89 insertions(+), 100 deletions(-) diff --git a/client/src/collapsing-headings-spec.md b/client/src/collapsing-headings-spec.md index cca9c5a4..83eaa636 100644 --- a/client/src/collapsing-headings-spec.md +++ b/client/src/collapsing-headings-spec.md @@ -63,19 +63,19 @@ Definitions Rules ----- -1. **Disclosure:** use view-only `
` and `` elements for - Markdown content and the parts of a section inside doc blocks; code and - whole doc blocks use CodeMirror's folding (rule 5). The summary replaces - the button and shows ▾ when open and ▸ when closed, before the heading - text. These wrappers do not change which headings qualify or their section - boundaries. - The heading stays editable and retains its heading level for screen readers. - Visible summaries, including those in inactive doc blocks, are reachable - and can be left through page keyboard navigation without a mouse. Enter or - Space on a focused summary toggles it without editing the document. Its - accessible name identifies the heading, and its expanded or collapsed - state is exposed through the native disclosure semantics. Focusing a - doc-block summary leaves TinyMCE in its current block. +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. The heading itself stays outside, 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); the part of the section that + starts a later doc block is hidden without a summary of its own. + Visible summaries, including those in inactive doc blocks, can be reached + and left with the keyboard; focusing one leaves TinyMCE in its current block. + A click, Enter or Space on a summary toggles it without editing the document. + 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 and shows the collapsed marker ▸. The heading and its summary stay visible. Before closing, if the Client's text cursor or either end of its selection is in @@ -84,11 +84,9 @@ Rules This avoids reopening the section under rule 7. Hidden content cannot receive keyboard focus; an edit affecting it first reveals it (rule 8). 3. **Expand:** activating ▸ shows the section again. A subheading that was - collapsed before stays collapsed, unless it must open to reveal an edit - (rule 8). -4. **Markdown documents:** the section consists of the elements after the - heading in the document's contents, ending before the next heading of the - same or a higher level, or at the end of the document. + collapsed before stays collapsed and keeps its section hidden, including code + which both sections contain, unless it must open to reveal an edit (rule 8). +4. **Markdown documents:** the whole section is in the heading's `
`. 5. **Source files:** the same section boundary applies across code and doc blocks. A section may start and end in the same doc block. Otherwise it contains the rest of the heading's doc block, all intervening code and doc @@ -97,17 +95,17 @@ Rules file. Hiding part of a doc block leaves its other content visible. Code in a collapsed section is hidden, not deleted. The code and whole doc blocks in a section are folded with CodeMirror's own folding, so they show as - CodeMirror's fold placeholder (…). Clicking the placeholder, or a CodeMirror - unfold command such as Unfold All, expands the section like ▸. -6. **Never saved:** collapsing and expanding change only the Client's view; - they do not mark the document as edited or send document content. All - content, including hidden content, is kept. The generated `
` and - `` wrappers, their open state, and other collapse-only markup are - absent from content sent to the Server, the Markdown it produces, and the - saved file. Original document markup and attributes, including heading ids - and any author-written disclosure elements, are preserved. Cursor paths - and offsets describe the document without the generated controls and - wrappers. Moving the cursor under rule 2 may send a normal cursor update. + CodeMirror's fold placeholder (…). Clicking a placeholder expands the + outermost collapsed section that hides its content, like that section's ▸, + and no other section. CodeMirror's Unfold All expands every section. +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 `
` and `` elements, their state and + any other collapse-only markup are absent from content sent to the Server. + 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 @@ -120,19 +118,15 @@ Rules heading's level so that a collapsed section now holds the cursor. A line in a doc block that is only partly hidden 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, and this spec assumes - they will be made: in Markdown documents the Client doesn't yet follow the - IDE's cursor (`scrollToLine` is a `TODO`), and same-file links don't yet - work in source files (their tests in `overall_5.rs` are ignored). + Two of these cases, the IDE's cursor in Markdown documents and same-file + links in source files, need fixes in the Client first; this spec assumes they + will be made (see Implementation). 8. **Edits:** before a Client edit that would change hidden content, expand every section needed to reveal the affected content, then apply the edit with the same result as if that content had been shown. This includes Backspace or Delete merging across a collapsed section and replacing or deleting a selection that crosses one, in Markdown and source files. Undo - and redo are edits too. In example 1, with A collapsed, Backspace at the - start of C must reveal A's section before merging C into p2; selecting from - A to C and typing must reveal the affected hidden content before replacing - the selection. + 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 @@ -145,27 +139,19 @@ Rules the IDE and the re-translations the Server sends on its own (after some saves, or when a cross-referenced target changes). It applies to both incremental updates and full content replacements that rebuild the view, - before resolving cursor and scroll targets (rule 7). Discard keys with no - match; unmatched new headings start expanded, though a collapsed ancestor - may still hide them. Thus an IDE rename or level change normally loses that - heading's collapsed state. - Occurrence matching is deterministic, but inserting or deleting an - identical heading may transfer the state to another occurrence, and a - heading whose text comes from a cross-reference gets a new key when its - target's text changes; tracking identity across such changes is out of - scope. Opening another file, closing - and reopening this file, or reloading the Client starts with all sections - expanded. An automatic full content update of the open file is not a reload. + before resolving cursor and scroll targets (rule 7). 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. Opening another file, closing and reopening this file, or reloading + the Client starts with all sections expanded. An automatic full content + update of the open file is not a reload. Out of scope ------------ * Remembering collapsed sections after the file is closed or the Client reloads. -* Commands to collapse or expand every section at once. -* Headings inside lists, block quotes and tables, which aren't headings by the - definition above. -* Tracking heading identity across updates from the Server beyond the - heading-key rule. +* 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. * Finding hidden text with the browser's own find; the Client's search covers @@ -200,55 +186,58 @@ Server, to the browser tests in [overall](../../server/tests/overall/). | 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 | 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`], `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 -------------- -* **Markdown documents** ([CodeChatEditor.mts](CodeChatEditor.mts)): the whole - document is one TinyMCE editor. Keep fold state separate from document - content. Any display-only DOM additions must be excluded from every content - extraction path, including raw saves and direct `innerHTML` reads (rule 6). - `data-mce-bogus="all"` alone does not establish that these paths are clean. - Keep cursor paths consistent with the content sent to the Server. Display - changes must not create document edits or undo entries; user edits retain - the editor's normal undo behavior. -* **Source files** ([CodeMirror-integration.mts](CodeMirror-integration.mts)): - fold the code and whole doc blocks of a section with the folding in - `@codemirror/language`, which `basicSetup` already includes. `foldEffect` - and `unfoldEffect` add and remove a fold, and `foldState` maps it through - edits. `foldState` also clears a fold that a deletion touches or that the - selection head moves into (`clearTouchedFolds`), which gives rules 7 and 8 - for code. A fold starts and ends at doc-block boundaries, so it never - partly overlaps a doc block's own `Decoration.replace` widget; the parts of - the first and last doc blocks that belong to the section are hidden inside - those blocks (rule 1). `DocBlockWidget.eq` must compare that state, so that - `toDOM` and `updateDOM` redraw the block, including when TinyMCE moves into - or out of it. See the CodeMirror - [folding reference](https://codemirror.net/docs/ref/#language.foldEffect). +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 doesn't let Backspace or Delete cross the edge of a `
`, + even an open one. Before such an edit, remove the generated elements, + keeping the content; add them again afterwards (rule 8). + * Raw saves and `innerHTML` reads both include the generated elements, so + remove them from each copy of the content the Client extracts (rule 6). + * TinyMCE's `searchreplace` selects text in a closed `
` without + opening it. Open the section (rule 7); its Replace All 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 + covers code and whole doc blocks only. + * Compute the folds from the set of collapsed headings. Two headings can need + the same fold, which `foldState` stores once, and 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`. + * The default placeholder opens the first fold in its line block, and adjacent + sections share a line block. Give each placeholder its own section, using + `codeFolding`'s `preparePlaceholder` and `placeholderDOM` (rule 5). + * `foldState` opens a fold when the selection's head moves strictly inside it. + It doesn't for the fold's first position, which is where `scrollToLine` puts + the cursor for the first hidden line, or for the end of a file whose last + section is collapsed; the Client must open the section there (rule 7). + * `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:** redraw a doc block after a toggle and after + TinyMCE moves into or out of it, without marking the file dirty (an + unannotated `updateDocBlock` effect does). * **Updates from the Server:** Markdown content is reset with `setContent`; a - full source update destroys and recreates the CodeMirror view, while a - source diff uses transactions. Re-translations (`is_re_translation`) take - the same paths. A diff maps CodeMirror's folds through its changes; a full - update recreates the view and its `foldState`. Restore collapsed state by - heading key after each path (rule 9), without inserting fold state into the - content used as the next diff's base. Then open any restored section that - still hides the cursor (rule 7), and only those sections. `foldState` clears - a fold only when a transaction sets the selection, so include `unfoldEffect` - for that section's fold in the same transaction. A cursor hidden inside a - doc block has no fold over it: clear the heading's collapsed state, so that - `DocBlockWidget.eq` returns false and the block is redrawn. In Markdown - documents, leave that section's `
` open. - Existing heading ids serve cross-references and must remain unchanged. -* **Cursor, scroll and edits:** in source files, setting CodeMirror's - selection to the IDE's cursor line opens the folds around it (rule 7). - 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 - test 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` and TinyMCE's - `searchreplace` must open the sections hiding their target, and its Replace - All is an edit (rule 8). Reveal hidden content before an edit affects it - (rule 8), including edits crossing doc-block boundaries. - + full source update recreates the CodeMirror view; a source diff uses + transactions. Re-translations (`is_re_translation`) take the same paths. + After each one, restore collapsed state by heading key (rule 9), leaving out + every section that would hide the cursor (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. From 1799c08485bc931f61f7d80306309e8dad0ff92d Mon Sep 17 00:00:00 2001 From: Askar Oralkhan Date: Tue, 1 Dec 2026 19:36:03 +0500 Subject: [PATCH 17/22] submission: round 4 review for Askar Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011e1fmFdDpHsiQY8RfwhXTv --- submission.md | 148 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 59 deletions(-) diff --git a/submission.md b/submission.md index b3eebfe5..a3fc33d1 100644 --- a/submission.md +++ b/submission.md @@ -15,9 +15,10 @@ GitHub userid: askaroralkhan #### Contributions -Wrote the first draft of the spec, ran the three spec review rounds and split -their findings among the team, simplified rules 7 and 9 after round 2, and -wrote this file and the pull request. +Wrote the first draft of the spec, ran the four 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 round 4, and wrote this file and the pull request. #### Build and run test @@ -47,69 +48,98 @@ of the reviewed commit, so the reviewer could run `cargo`, `node` and | ----- | ------- | -------- | ----------------- | | 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 | Not applied yet; next: take heading keys from the Client's current content, keep the cursor out of content hidden by a Client edit or a Server update, limit link-following to Markdown until source-file links work, and cover TinyMCE's search and a keyboard route to doc-block buttons | +| 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 | #### Last specification review -Prompting Claude Opus 5.5, extra high effort (Claude Code 2.1.330), with -`Review the spec in client/src/collapsing-headings-spec.md.` produced the -following output. Strikethrough would mark output that we deemed incorrect or -irrelevant; we struck none. +Prompting Claude Opus 5.5, extra high effort (Claude Code 2.1.330), with the +prompt below produced the output after it. Strikethrough marks output that we +deemed incorrect or irrelevant: we keep `
`, as the instructor advised, +and a placeholder opens only the outermost section, so that rule 3 holds. -I found three problems that would cause wrong behaviour if the spec is implemented as written, and some areas the spec doesn't cover. The rules and examples agree with each other: examples 1–3, 6–8, 17 and 18 come out right under the section definition. +> Review the spec in client/src/collapsing-headings-spec.md. It relies on +> CodeMirror's own folding: read that code in +> client/node_modules/@codemirror/language (foldState, foldEffect, +> unfoldEffect, clearTouchedFolds, codeFolding, the fold placeholder) and the +> Client code that the spec names, and run code to check what the spec claims +> about them. The instructor penalises overspecification, so also say where +> the spec 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'm writing up the review now. I haven't edited the spec. + +I ran `foldState`, the height map and search's Replace All from the installed packages (language 6.13.1, view 6.43.15) in Node. Chrome and installing jsdom were refused here, so the **TinyMCE and DOM points (1 and 8) come from reading the code**. CodeMirror positions below use example 3 with doc block A at 0–3, the fold at 3–16, and C at 16. ##### Would cause wrong behaviour -**1. The heading key breaks for headings edited in the Client.** -- **The problem:** the key uses the heading text "in the HTML the Server sends". In example 11 (collapse A, edit its text, autosave), the Server's last HTML still has A's old text. If a re-translation follows, as it does in example 24, the old key won't match the new content and A expands. In source files it's worse: the active doc block's current text is held in TinyMCE, not in `DocBlockWidget.contents`, until autosave. -- **"Text" is ambiguous:** it could mean `textContent` or the inner HTML. The Server writes attributes unquoted (`ref=foo`, `server/src/ide/vscode/tests.rs:2171`); TinyMCE doesn't, so inner HTML won't match between them. -- **Cross-references:** an empty `` inside a heading takes its text from its target. A cross-reference re-translation, one of the cases rule 9 lists, can then change the heading's key. -- **Fix:** take the "before" keys from the Client's current content as it would be sent (no controls, math not rendered). Compare `textContent` with whitespace and ` ` normalised. List the xref case beside the duplicate-heading limitation. - -**2. The cursor can end up in hidden content without anyone collapsing.** Rule 2 only moves the cursor when a section is collapsed. Two other things can hide it: -- **Editing a different heading:** take `H1 A`, p1, `H1 C`, p3 with A collapsed and the cursor in C. Making C an `H2` or a paragraph pulls C and p3 into A's hidden section, cursor included. Example 17 only covers the reverse. -- **Server updates:** Markdown restores the selection as a list of child indexes (`client/src/CodeChatEditor.mts:400-412`, and `client/src/CodeMirror-integration.mts:539-545`). In example 19, a cursor in C (index 4) is put back at index 4, which is now p2, and p2 is hidden. -- **The examples avoid it:** the intro text says Server updates leave the cursor outside hidden content, so this case is never specified. -- **Fix:** a Client edit should never hide what it's editing; expand the section that would swallow it, as rule 8 does. After a Server update, move a hidden cursor to the end of the outermost collapsed heading without opening anything, as rule 7 does. - -**3. Following a link into a collapsed section of a source file depends on an existing bug being fixed.** -- **Why it fails:** `followLink` finds its target with `document.querySelector` (`client/src/CodeChatEditor.mts:734`). CodeMirror only renders content near the viewport, and doesn't render replaced (folded) ranges at all. A collapsed target is never in the page, so the Client can't tell which sections to open. -- **It's already broken:** the same-file link tests are marked `ignore` for this reason (`server/tests/overall/overall_5.rs:1290-1333`). Example 14 is Markdown only, so nothing tests the source-file case. -- **Fix:** either limit the link part of rule 7 to Markdown, with a `TODO:` saying when that limit can go, or require looking up ids in the doc-block contents held in CodeMirror's state. - -##### Not covered by the spec - -**4. TinyMCE's search.** The `searchreplace` plugin is enabled (`client/src/tinymce-config.mts:92`), and it's the only in-editor search in Markdown documents. The Implementation section only names CodeMirror's search and go-to-line. TinyMCE's search needs to open sections, and its Replace All edits hidden content. The spec should also say whether the browser's own find counts. - -**5. Keyboard access.** -- **Tab:** rule 1 deliberately doesn't promise a Tab order, but example 5 says "Tab to A's button". In source files, Tab indents code (`indentWithTab`, `client/src/CodeMirror-integration.mts:1846`) and doc-block contents can't be tabbed to. So there's no stated keyboard route to a doc-block heading's button. -- **Space and Enter:** pressed on a button inside a TinyMCE editor, they also reach TinyMCE's own key handling. Example 5 should check that the content is unchanged and the document isn't marked dirty. -- **Screen readers:** the button's only accessible name is the ▾/▸ symbol. Give it an `aria-label`, and add a collapsed heading to the fixtures used by `overall_a11y.rs`. - -**6. Cases no example covers:** -- **Rule 2's cursor move:** not covered in either document type. -- **Source-file saves and dirty state:** no example covers either, yet the riskiest content-leak paths are source-file only: reading inactive blocks' `innerHTML` (`:826`), TinyMCE→div via `save()` (`:1527`), and div→TinyMCE via `resetContent(contentsDiv.innerHTML)` (`:1547`). The Tests bullet asks for save checks in both document types, but there's no example to give the source-file checks an expected result. -- **New headings:** a heading created in the Client, by changing a paragraph or pasting, getting its button. -- **Undo and redo:** TinyMCE undo replaces the editor's content, so the display-only buttons must be put back afterwards, as after `setContent`. - -**7. The Tests bullet doesn't describe how Client tests run.** -- **Not just `test.py`:** the suite runs on any page loaded with `?test` (`client/src/CodeChatEditor-test.mts:21-24`), once per page load, and then deletes itself. -- **Markdown fixture:** the `test_client` test in `server/tests/overall/overall_1.rs:681-746` loads `test.py` and runs the suite. A Markdown fixture placed beside it won't run until it gets its own test like that. -- **Cheaper layer:** example 12 and the outgoing-HTML part of example 10 check Client-side behaviour (the cursor path and the raw save). They could be Client tests, which AGENTS.md prefers to the slow browser tests. - -##### Nits -- **Paragraph breaks:** the second paragraph in rules 6, 8 and 9 has no blank line before it, so each renders merged into the first. -- **Rule 6:** "Check both raw TinyMCE saves…" is test guidance that repeats the Implementation section. It belongs under Tests. -- **"Every update":** "the IDE sends a line number with every update" isn't accurate. `cursor_position` is optional. -- **Review notes:** `collapsing-headings-daniil-reviews.md` still says rule 7 reflects the older cursor-expansion behaviour, but rule 7 has been rewritten since. - -##### Confirmed correct -- **Heading definition:** `.CodeChat-doc-contents` is the right container in both document types. -- **Rust headings:** `///` is a doc-block delimiter for Rust (`server/src/lexer/supported_languages.rs:372`). -- **Update paths:** the three update paths are as described (`setContent`; destroying and recreating the view; diff transactions). -- **Markdown cursor:** `scrollToLine` really is a `TODO` for Markdown. -- **Gather lists:** they're inserted after their heading, not inside it (`server/src/processing.rs:2329`), so they don't affect heading keys. -- **Line width:** no prose line is longer than 80 characters. +1. **Rule 1 (66–78), rule 8, example 8: `
` wrappers conflict with TinyMCE 8.10.1.** + - **Deleting:** TinyMCE blocks Backspace across a `
` edge, even an open one (`tinymce.js:32831`, `:32880`). This check runs before block merging (`:32986` vs `:33002`). Backspace at the start of C therefore can't merge into p2, even with everything expanded. + - **Toggling:** TinyMCE cancels every click inside a `
` (`:35543`), so native toggling doesn't work in Markdown documents. + - **Saving:** raw saves strip only temporary attributes and `bogus="all"` elements (`:15154`, `:15258`), so wrappers leak into them. + - **Structure:** the spec never says whether the heading is inside ``. If it is, `focusin` refuses to move TinyMCE there (`CodeMirror-integration.mts:1340`), so clicking the heading can't edit it. + - **Example 4:** hidden p2 has no heading in its block, so its `
` would show the browser's default "Details" label. + - **Fix:** ~~specify behaviour only: a keyboard-reachable control that names the heading, exposes its state and isn't content. Suggest hiding elements with an attribute registered through `serializer.addTempAttr`, plus a `bogus="all"` button.~~ + +2. **Rule 7, example 7, Implementation (218–221, 242–243): the IDE's cursor doesn't always open the fold.** + - **Cause:** `clearTouchedFolds` tests strictly inside (`a < head && b > head`). A doc block's `to` is the next line's `from`, and `scrollToLine` uses `line.from`. + - **Run:** the cursor on the first hidden line (3) leaves the fold at 3–16; lines at 9 and 10 clear it. Example 7 fails if `code1` is one line. + - **End of file:** with the last section folded, a cursor at the end doesn't open it, and text typed there appears outside the fold. An anchor or secondary cursor inside also leaves it folded. + - **Fix:** say that `scrollToLine` opens every section containing the cursor's line, first and last lines included. Don't apply that to all selections, because position 3 also means "end of doc block A" (`selectDocBlockEdge`). + +3. **Rule 5 (99–101): clicking a placeholder can open the wrong section.** + - **Cause:** the click handler calls `findFold` over `lineBlockAt`, which takes the first fold in the line block. Folds that end at doc-block boundaries join consecutive collapsed sections into one line block. + - **Run:** with folds 1–7, 8–14 and 15–20, the line block is 0–20, and all three placeholders resolve to 1–7. The fold gutter and `unfoldCode` use the same lookup. + - **Fix:** require that a placeholder opens its own section, using `codeFolding({ preparePlaceholder, placeholderDOM })`. Limit the command promise to Unfold All, and add an example with two adjacent collapsed sections. + +4. **Rules 3 and 5: two headings can share one fold.** + - **Case:** with doc block [`H1 A`, `H2 B`], code, [`H1 C`], A and B have the same range. This is common: AGENTS.md's template puts `Imports` and `### Standard library` together. + - **Run:** `foldExists` drops the second fold, and one `unfoldEffect` removes the only one. Expanding A also reveals collapsed B's code, against rule 3. It is also unclear which section the placeholder expands. + - **Fix:** derive folds from the set of collapsed headings, and keep a fold while any heading needs it. ~~Clicking a placeholder opens every section hiding that content.~~ + +5. **Implementation (234–237): "include `unfoldEffect` … in the same transaction" fails on a full update.** + - **Run:** `foldState` adds folds after processing unfolds, so `[fold, unfold]` and `[unfold, fold]` both leave 3–16 folded. When the fold already exists (a diff), only `[fold, unfold]` opens it. + - **Fix:** don't restore a section that hides the cursor. That also removes most of lines 234–240. + +6. **Implementation (231–234): a mapped fold can be stale.** + - **Run:** inserting a line at 3 moves the fold to 7–20, leaving the new line visible. Restoring adds 3–20 beside it, and expanding A then leaves 7–20 hidden. A Server test sends such an insert (`vscode/tests.rs:766`). + - **Fix:** after each update, remove all section folds and add recomputed ones. + +7. **Rule 8, Implementation (218–221): "gives rules 7 and 8 for code" is too strong.** + - **Run:** only `delete` events clear a touched fold. With no selection change, type, paste, move, undo and redo events don't. Replace All changed hidden text to `ZZZZ1` and `ZZZZ2` with the fold still closed. + - **Fix:** drop the claim. Require any Client edit touching a fold to open it, for example through a transaction extender. Server diffs are exempt. + +8. **Implementation (224–226, 237–239): the `DocBlockWidget.eq` recipe isn't enough.** + - Moving TinyMCE between blocks doesn't use `eq`, `toDOM` or `updateDOM`; `focusin` rebuilds the DOM itself (`:1516–1551`). + - `updateDOM` returns early for a user-edited TinyMCE block (`:516`). Otherwise it calls `setContent`, which produces spurious `Dirty` events according to the comment at `:1540`. + - An unannotated `updateDocBlock` marks the file dirty (`:1649`), against rule 6. + - **Fix:** replace it with "redraw after a toggle and after TinyMCE moves, without marking the file dirty". + +##### Smaller errors + +9. **Line 68:** "replaces the button" refers to an old draft. **Fix:** delete it. +10. **Lines 235–236:** "only when a transaction sets the selection" contradicts 218–220 (deletions clear folds too). **Fix:** delete it with finding 5. +11. **Line 247:** it says "the ignored test", but there are three. **Fix:** use the plural, as line 126 does. +12. **Line 211:** this is true for `innerHTML` reads and cursor paths, but raw saves do strip `bogus="all"`. **Fix:** say so, or delete it. + +##### Where to simplify + +13. **Rule 7:** keep the first two sentences, the partly hidden doc block and the scroll sentence. Move the two unfixed Client cases to the Implementation TODOs, which already repeat them. +14. **Rule 8:** delete the example 1 walkthrough (132–135); example 8 covers it. +15. **Rule 9:** state the key rule and that unmatched headings start expanded. Cut lines 152–156 to "identical or renamed headings may lose or swap state". +16. **Rule 6:** remove its overlap with lines 30–32, 209–214 and 234; state "never saved" once. +17. **Rule 4:** delete it; the Section definition already says this. +18. **Implementation:** keep the constraints found by testing (2–8) and leave the mechanism to the implementer. Out of scope can drop lines 165–168, which repeat the definitions and rule 9. + +##### Claims that hold + +- `basicSetup` includes folding and shares the Client's `@codemirror/language` instance. +- Cursors strictly inside a fold clear it, and nested folds unfold separately. +- The Markdown `setContent` path and the full and diff source paths match the code. +- `scrollToLine` is a `TODO` for Markdown, and `followLink` uses `document.querySelector`. + +The scripts are in `/private/tmp/ch-review`; run each from the worktree root as `node