Skip to content

fix: land a double-click on a README's HTML on its own line in the editor - #7315

Merged
max-sixty merged 8 commits into
mainfrom
agent-a2cb589895092f4bc
Nov 26, 2026
Merged

max-sixty merged 8 commits into
mainfrom
agent-a2cb589895092f4bc

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A double-click in a Markdown file's preview now lands on the right line when the file holds HTML. Since #7310 the preview draws a file's HTML as GitHub does, but the double-click from #7297 placed the file's tokens with html: false, so an HTML block's words were its tags, which never appear in the preview, and a double-click inside a centred <p align="center"> header or an HTML fold landed on the next Markdown block's line.

Placement now parses a file the way the drawing did: markdownSourceOffset takes the rendering's html flag, and each caller names it (the preview true, lf-draft false), which the type check enforces. An HTML block is placed whole and aligned by the words its source draws: the text outside markup (tags, comments, declarations, script and style), with character references decoded and <br> as a line break. So a word never lands in an attribute or comment that spells it, text the sanitizer drops takes no part, and a large HTML table maps in milliseconds. Text the browser's parser moves out of source order, such as foster-parented table text or a <pre>'s first newline, still sends a click in that block to the next block, and a half-glyph click beside markup that spans lines inside a blockquote, or beside a multiline comment, can take the neighbouring line. The mapping pairs words in document order rather than elements with tokens, so Markdown that a fold wraps maps as before.

On 200 popular READMEs drawn through markdownFileFragment in Chromium, all 2,246 sampled words now map to the word's exact source position; before, 1,779 landed on a line holding the word. A lookup's p99 is 13 ms; a 160-row HTML table takes 0.7 ms, where aligning against its tags took 255 ms.

Follows the parent session's request to fix the double-click for #7310's previews; reviewed in four Codex passes.

Tests: the browser double-click test's README gains a centred header with a title, comment and <style> spelling its word, and a fold with Markdown inside; it fails without the change. A runtime case covers the same mapping, with quoted >, character references with and without semicolons, and both sides of markup that spans lines.

This was written by Claude Code on behalf of max-sixty

@max-sixty
max-sixty merged commit 662a007 into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-a2cb589895092f4bc branch November 26, 2026 22:12
leaf-agent added a commit that referenced this pull request Nov 27, 2026
…7336)

`test_a_double_click_on_the_rendered_copy_types_at_its_line_in_the_editor`
has failed on `main` since #7317, which landed ten minutes after #7315
added the test. #7317 switched a Markdown file's preview to DOMPurify's
defaults, which keep the file's `<style>`. The test's README holds
`<style>.Gizmo { color: red }</style>` ahead of
`<strong>Gizmo</strong>`, so `word_point` took the style's text node
first. That range draws no box, so the double-click pressed the window's
corner. It selected the page's heading ("Notes"), and the editor never
took focus.

`word_point` now skips any text that draws no box and raises if no drawn
copy of the word exists. The product's double-click mapping needs no
change: with the press on the visible "Gizmo", every word in the test
lands on its line. The test fails on `main` and passes with this change.
So do the other callers of `word_point`, in `test_reading_place.py`,
`test_draft_editing.py`, `test_render_files.py` and
`test_threads_in_panel.py`.

Refs #7334 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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