Skip to content

Fix the cursor, the selection and the preview in a presentation's editor - #424

Merged
Swordlash merged 4 commits into
mainfrom
slide-row-cursor
Dec 3, 2026
Merged

Swordlash merged 4 commits into
mainfrom
slide-row-cursor

Conversation

@Swordlash

@Swordlash Swordlash commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

WP5.145, the first two of three faults of a presentation's editor the owner reported, each with its own cause and its own commit. The third (the preview following the cursor) was in this pull request at first and is cut off into the next one, stacked on this branch, after the first review round found six things in it and none in these two.

  1. "Klikanie w edytor prezentacji (slides) znika kursor, muszę zrobić strzałkę żeby się pokazał"; "słowa też nie mogę zaznaczyć kliknięciem … zaznaczenie … znika i się pojawia jak przeciągam kursor".
  2. A video at 240 frames a second of the side-by-side preview jumping between two layouts for as long as it is watched; one letter added to the text stops it.

1. The cursor and the selection in a slide's row

Cause. A row's transaction is sent on to the hidden master editor (forwarded in web/src/editor.js), and it copied the user event select.pointer. CodeMirror writes the page's selection into any view told of a pointer selection, even one without the focus, so the hidden master took the page's selection away from the row, then read its own selection back and moved the row's cursor. It has been so since the rows were written (2026-11-12); it is not from the library's pin. Fix: a click's selection is forwarded to the master as a plain select.

What a real click did before: in a row that had the focus, the selection was right in CodeMirror but the page's selection sat in the hidden master, the caret had a box of 0×0 and a key typed went elsewhere; a click in another open row drew the caret at the row's start; a double click selected a word that was not drawn; a drag drew nothing and ended at the wrong place.

One drag of 12 steps in a row before after
selection transactions into the row not from the pointer 11 0
events telling the cursor's line, each a render of the editor 21 0
DOM mutations outside CodeMirror 22 0

A document's editor and a presentation's raw text had neither fault.

2. The preview that never came to rest

Cause, a loop of two halves. wikiFitMeasure (wiki-app/jsbits/slide-fit.js) sets a card's scale from the preview's inner width and is run again by a ResizeObserver; the side-by-side pane has a fixed height and overflow-y: auto, and a card's height follows its scale. At the threshold the scrollbar comes, the card shrinks, the scrollbar goes, the card grows. Measured at a window of 1800×830 to 842 with classic scrollbars: the scale flipped between 0.6748 and 0.6602, 58 to 60 times a second. Fix: scrollbar-gutter: stable on that pane, so the measure does not depend on what it changes. Idle afterwards: 0 measures, 0 changes of scale, 0 mutations. The loop never reached the editor's renders (its messages were deduplicated), so it did not cause the first fault.

Known and left

  • (2) has no automated test here: the suite's Chromium hides its scrollbars, so the loop cannot close there. The 60 a second to 0 was measured with a script and classic scrollbars. An example asserting the pane's computed scrollbar-gutter comes with the next pull request, where its helper was written.
  • In (1)'s tests the clicks of the caret example are the driver's own, on the row's text element; the double click and the drag are dispatched mouse events (the driver has no double click, and CodeMirror strips the driver's mark off a line element).
  • One example of the slide rows ("adds a slide after the row last typed in") announced "The slide added." once under a load of 27 and passed alone and in three group runs; it reads the rows' headers before they are updated, in code this change does not touch.
  • The faint text seen on a slide in the owner's photo: the DOM holds every card, the ones not shown hidden and unpainted; most likely the camera.

Tests

  • (1) Real clicks on a closed row's header, in a focused row's text and in another open row: where the caret is drawn and that typing lands there; a double click and a drag in a row, in a document's editor and in raw Markdown. Without the fix the row's examples fail and the other two editors' pass.

Verification

Run locally, on the three-fault head this was cut from: build-native, build-wasm, format-check, lint; the browser groups "A presentation in the editor", "Room to write in" and "A presentation embedded in a page" (97 examples). This head is its first two commits; CI is its gate. The other browser suites and the smoke suites are left to CI.

Codex

  • Round 1 (9a47f69, gpt-6.2-sol, high, on the head with all three faults): six findings, five in the following of the cursor and one that the scrollbar's fix is not exercised by its test (said above); none in the cursor and selection's fix. The following is cut off into the next pull request, where the five are fixed; this one is its first two commits (2516115).

  • Round 2 (2516115, which differs from the head after it only in the changelog entry's title; that title was 89 bytes where 80 are allowed and failed CI's build of "What's new", and is shortened in cd64a47): two findings. Being fixed: a click's selection and an arrow key's now both carry the event select, so the history joins them and Undo Selection after a key and a quick click skips the place between; the click gets an event of its own that is neither a pointer's to the hidden master nor a key's to the history. Left as said above: no test closes the scrollbar's loop in the suite's browser.

(rounds are added here)

🤖 Generated with Claude Code

https://claude.ai/code/session_01HnFn8HVAncUyJ6jU4yhnRM

In a presentation's slide mode each open row is a CodeMirror of its own,
and every change of a row's selection is sent on to the editor's own
CodeMirror, the master, which is hidden. The row sent a click's selection
on marked as a click's ("select.pointer"). CodeMirror writes the page's
selection into any view told of a click's selection, focused or not, so
the hidden master took the page's selection away from the row: the row
kept the focus but drew no caret, a double click's word and a dragged
selection were not drawn, and the master then read its own selection
back and moved the row's cursor, so that a click in a row without the
focus left its cursor at the row's start and a key typed went elsewhere.
An arrow key drew the caret again because the row then wrote the page's
selection itself.

The row now sends a click's selection on as a plain "select". The
browser tests click in a row's text with the driver's pointer, and
double-click and drag with mouse events, in a row, in a document's editor
and in a presentation's raw Markdown; the last two never had the fault.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HnFn8HVAncUyJ6jU4yhnRM
The editor's preview of a presentation scales each slide's card to the
width inside the pane, measured whenever the pane changes size
(wiki-app/jsbits/slide-fit.js). That width depended on the pane's
scrollbar, and the scrollbar on the cards' height. At the threshold, a
slide with notes just as tall as the pane, the scrollbar came, the card
was scaled down and no longer overflowed, the scrollbar went, the card
was scaled up and overflowed again: the slide changed size at every
frame, about 60 measures a second with nobody doing anything. The pane
now keeps the scrollbar's room whether it scrolls or not
(scrollbar-gutter: stable), so the width the cards are scaled to no
longer depends on what the scale changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HnFn8HVAncUyJ6jU4yhnRM
@Swordlash
Swordlash merged commit 1646a1c into main Dec 3, 2026
14 checks passed
@Swordlash
Swordlash deleted the slide-row-cursor branch December 3, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants