githubnext/chopinPublic

Let's compose rich plans together

Guard editor scroll position across Enter #368

MergedMaggieAppletonmerged 1 commit intomainfromrefs/pull/368/head
  1. MA

    ## Why

    The research-composer work reported that pressing Enter mid-document made the document scroller (`[data-plan-scroll]`) jump toward the bottom (627 to 2445 px), and that the slash menu's Enter did it too.

    I could not reproduce that with Enter. The jump comes from **End**, not Enter. The reporting test (PR #355) presses `End` and then `Enter`. On macOS, Chromium maps End to "scroll to end of document" and leaves the caret where it is. So the scroller jumps to the bottom on End. Enter then scrolls back far enough to show the caret. On Linux CI, End moves the caret to the end of the line, so the jump only happens on a Mac.

    A plain `contenteditable` inside an `overflow: auto` div does the same thing on macOS Chromium (300 to 776, which was the bottom, on End, with the caret not moving), so Chopin's code is not involved.

    The scroll write-back in `PlanEditor` is not involved either. Enter fires no scroll events at all. PR #355 already fixes that write-back separately.

    ## What changed

    - No product code changed. - Two browser tests in `e2e/editing.e2e.ts`: - **Enter mid-document keeps the caret line where it was.** It puts the caret at the end of a middle passage, then presses Enter, types `/code`, and presses Enter again. The scroller and the passage must each move by no more than 4 px. - **Typing past the bottom of the view scrolls the caret into it.** It presses Enter 20 times at the last passage, types some text, and checks that the scroller moved and the typed line is inside the scroller. - The tests place the caret by clicking the right edge of a one-line block. That works on every platform, unlike End.

    ## Screenshots

    Measurements in headless and headed Chromium, 1440脳900, 40-passage document. The caret starts at the end of "Passage 15." with `scrollTop` 204.

    | Keys | scrollTop | | --- | --- | | Enter, `/code`, Enter | 204, 204, 204 (no movement) | | End (macOS) | 1978, caret not moved | | End, then Enter (macOS) | 1978, then 626 |

    Enter, then the slash menu's Enter: the document stays put.

    ![Enter and slash Enter](https://github.com/user-attachments/assets/ada14cbf-87d1-4906-8c5f-52e2257de7e0)

    macOS End alone jumps the scroller to the bottom. This is the reported jump.

    ![macOS End](https://github.com/user-attachments/assets/00be8cda-c3d3-4a0c-a618-f174b44af7e5)

    ## Testing

    - `bun run ci`: pass. `bun run types`: pass. - Final rebased head `f5bf5c83` passed hosted validation, browser E2E (including both new geometry assertions), and container checks. - I ran the same test bodies against a local fake-GitHub server (port 8852): both pass. I checked that the first test fails when `End` is pressed before Enter: the scroller moved 1739 px, against the 4 px limit. - WebKit is not installed locally, so this was checked in Chromium only.

    馃 Generated with [Claude Code](https://claude.com/claude-code)

  2. MaggieAppletonreferenced this in Keep the research composer visible as one surface #355last month on GitHub

  3. MaggieAppletonhead-ref-force-pushed f5bf5c8350f4last month on GitHub

  4. MaggieAppletonmerged 2624ff0ab7e1last month on GitHub

  5. MaggieAppletonclosedlast month on GitHub

  6. MaggieAppletonhead-ref-deletedlast month on GitHub