Repository navigation
feat: double-click a word in a file's Markdown preview to type at its line in the editor - #7297
Merged
Merged
Conversation
… line in the editor A Markdown preview bound with `for` to the file editor now takes a double-click on a word to the editor, with the caret at the start of that word's line in the file, as a double-click on VS Code's preview does. The user picked this design. It lands on the word's own line rather than its block's first: a paragraph's later source line, a list item, a line of code, a table row. The double-click's second press selects no word, so neither a stray selection nor the comment box it opens stays behind in the preview. The preview follows the route a link to `#<editor>:<binding>:<line>` already takes (`navigateToDatum`), so focus, history and the line's centring are the editor's. What the double-click acts on: - a plain primary double-click on text; a picture, a modified double-click, and one whose first click went to a link or control keep their native behaviour. A link that scrolls the preview no longer lets the second press land on other words and move the editor too. - a preview whose `for` names the editor. A written or `source`-bound preview knows no editor, and its double-click still selects a word. The reader reaches the same caret in the editor itself, so the double-click needs no keyboard or touch route of its own. The rendered word finds its source offset through `markdownSourceOffset`, the alignment `lf-draft` already uses to open its editor at a clicked caret, rather than a second block-to-line mapping. Two changes to that shared mapper: - It takes the source as a parameter rather than reading `data-lf-source-words`, which only a draft's body carries; `lf-draft` passes the attribute. - A fenced block's words align from the line after the opening fence, so a command whose first word is the fence's language (`sh` in a fence of shell commands) maps to its own line, not the fence. This applies to a click in a draft too. `placedMarkdownTokens` read every block placed before each inline to find the container markers on its first line, which made placing a file's tokens quadratic. It now reads only the blockquotes and list items open around the inline. In Chromium, placing 1,000 / 5,000 / 10,000 blocks went from 18 / 294 / 1,108 ms to 9 / 39 / 73 ms, and the double-click's whole lookup takes 10 / 44 / 85 ms. Its output matched the old code's on 770 placements: the shared Markdown case files, every Markdown file in the repository, and nested, lazy and mixed lists and quotes, in both readings. The file editor's author instructions and its developer example each say the double-click exists, in one sentence. Tests: a browser test double-clicks words in a paragraph's second source line, a list item, a fenced command and a table row, and checks the line, the caret's column and that the preview keeps no selection; a double-click on selected words still jumps; one whose first click followed a link only follows the link; a written preview's double-click selects its word. It fails without the double-click, without the first-click guard and when a selection blocks the jump. A runtime case holds the fence alignment, and fails without it.
leaf-agent
previously approved these changes
Nov 26, 2026
# Conflicts: # examples/developer/file-editor.html
leaf-agent
approved these changes
Nov 26, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…ith `source` #7297 lets a double-click on a word of a Markdown preview bound with `for` to the file editor put the caret at that word's line; a preview bound with `source` names no editor, so it keeps the browser's double-click. The parent session's review chose that, beside an editor, the preview keeps `for` the editor: it shows each save, follows the open file of an editor of several, and takes the double-click, with no new name. A widget on a page with no editor binds the file with `source`. So the file-editor example's preview is back on `for="research-file"`, its Changes tab keeps `after="research-notes"` and follows the file on disk, the agent's writes included, and the file editor's author instructions and `lf-text-document`'s say which binding goes when. These correct which binding each case takes and move no goal, so they were not scored.
This was referenced Nov 26, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
A file a page binds with `leaf file bind` is now a data source under its
binding's id. Its value is `{key, name, text, revision}` under the
`text-document` contract. So `<lf-text-document source="notes"
preview="markdown">` or `<lf-diff before="notes-head" after="notes">`
shows every write to the file, whoever makes it, and works with no
editor on the page. A comment on either records the source's revision.
The revision digests the value, as every source's does. The run digests
the path, the label and the file's stat, so every write reaches the tab.
`leaf data set` and `leaf data clear` refuse a bound id, and `page
check` refuses an input of another contract that binds one
(`file-contract`).
The editor keeps reading and saving through `boundFile`. It owns the
reader's unsaved draft, and the copy the page receives can lag the
editor's own save. A preview beside an editor still binds the editor
with `for`, which keeps #7297's double-click to a line. `source` is for
pages with no editor.
To weigh: the hosted site's first-visit state and exports now carry the
bound files that published markup binds, with the data version of
exactly those. Two rare paths stay open. One is a hand-crafted comment
on a file bound after the page's markup was checked. The other is that
the file-contract check doesn't reach samples or messages.
Max picked this ("B") on a findings page. Checked agent writes stay in
#7292. Codex reviewed it over five rounds. Tests: model tests of the
source, the door and first visits; browser tests of the preview, the
diff, the editor and the double-click; `pnpm run test:runtime`.
> _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…ures and files beside it (#7310) The maintainer picked rendering the HTML GitHub allows in a file's preview, and on loading the pictures a file names beside it wrote: "why limit to these files? why not just allow anything the server can reach? I'm not sure we're really designed to have a proper sandbox at this point, we shouldn't add complication unless we're actually tight here". Of the 197 most-starred Markdown READMEs, 81% hold raw HTML, which the preview printed as tags, 46% name pictures by a path beside the file, which it couldn't load, and 80% link to another file by a path, which took the page itself to a missing address. - markdown.js gains `markdownFileFragment`, a file's reading with HTML, kept to GitHub's allowlist by DOMPurify 3.5.0 (31 KB, 12 KB compressed), which loads for the first file holding HTML. Beyond GitHub's list it drops `accesskey` and `tabindex`, which would rebind the page's keys and tab order, `data-` attributes, which Leaf's own marks use, and every class but a code block's language and a task list's, `rel`, which could keep an opener for a page a link opens, and the attributes that name another element by id, as `for` and `aria-labelledby` do, which could name one of the page's; an `id` or `name` takes GitHub's `user-content-` prefix, a style stands only as a table cell's alignment, which the reading writes so, and an `<input>` only as a disabled checkbox. The host's links and pictures apply after the sanitizer, to the file's HTML links as to its Markdown ones. Drafts and messages keep showing tags as text, since Python draws a draft's body too and has no sanitizer. - `boundFile(binding).beside(path)` gives the address `/api/files/<binding>/beside?path=<path>`, where a live page's server answers the file at that path from the bound file's folder, `../` included, or null where the page can't reach its server's files, as in an export. It answers any file it can read, but only to a request carrying the page's key, so a sample's capability and the website's container answer none, and never from Leaf's own state home, which holds each page's connection credentials that a page's scripts never receive. Text answers as text/plain, so a linked file shows rather than downloads, and every answer is sandboxed by `Content-Security-Policy: sandbox`, so an SVG a README names, opened on its own, runs no script as the page. A preview of a file the page binds, named by its value's `key` as a bound file's source (#7306) and its editor both name it, resolves a picture's `src` and `srcset` and a link to another file through it, opening a linked file in a new tab. Asking by the binding keeps the file's host path out of the browser, as the file editor always has; an earlier version handed the browser an address spelling the path. - A link to an anchor the file names, as `<a name="top">`, lands on it as a link to a heading does: the preview carries the file's ids and names as places of its own (`data-lf-place`) rather than page ids. A fold the reader opened stays open as they type inside it: a redrawn fold takes the state of the drawn one with its summary, within the same file. A table cell an HTML table aligns with `align`, as 27 of the READMEs do, keeps that alignment, which the reading face's `text-align: start` overrode on every page. - The preview's pictures stand bare, without the frame the reading face draws round a picture, as on GitHub. - An image sized by its `height` alone keeps that height on every page, drawn whole within it where its container is narrower: base.css forced `height: auto` on every image, which drew 167 logos in 35 of the READMEs at their files' size. No page in the corpus has such an image. On sparkjoy's README all 20 pictures load and no tag shows as text, in Chromium and Firefox. Left as they are, each rare: a double-click on a file's HTML text can put the editor's caret on the wrong line, since #7297's source mapping parses without HTML, which the editor session that built it is changing next; two previews whose files group folds under one `<details name>` share that group; an `<a>` with both `id` and `name` answers only its id; a `.svgz` picture doesn't draw; a live preview whose value's `key` names no binding asks the server for its pictures and gets none; after a rebind to another file, a picture at the same path can show from the browser's cache until a reload; a reference keeps no `#fragment`, and one whose `..` passes through a missing folder, or whose name mixes a bare `%` with escapes, finds no file. Tests: the preview's browser test plants a fold it then types inside, a centred picture beside the file, a link to another file and to a named anchor, an aligned table, a script, a handler, a `javascript:` link, an opener, a styled div with Leaf's class, data attribute and a page id, a text field and a task list; a runtime test holds a host's moved picture in place; a model test reads a picture above the bound file's folder beside its binding and checks the sandbox, the key and Leaf's state home. A written passage's test escapes its `<missing>` placeholder, which GitHub's reading drops as an unknown tag. Reviewed in five Codex passes. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…itor (#7315) 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_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Markdown preview bound with
forto the file editor now takes a double-click on a word to the editor, with the caret at the start of that word's line in the file, as VS Code's preview does. It lands on the word's own line (a paragraph's later source line, a list item, a code line, a table row), follows the route a link to#<editor>:<binding>:<line>already takes (navigateToDatum), and its second press selects no word, so no stray selection or comment box stays in the preview. A written orsource-bound preview names no editor and keeps native double-click selection; so do a picture, a modified double-click, and one whose first click followed a link.The word finds its source offset through
markdownSourceOffset, the alignmentlf-draftalready uses for a clicked caret, rather than a second block-to-line mapping. Three changes to that shared code are worth a look: it now takes the source as a parameter; a fence's words align from the line after the opening fence, soshin a fence of shell commands maps to its command, not the fence (drafts too); andplacedMarkdownTokensreads only the blockquotes and list items open around an inline instead of every earlier block. That last one was quadratic: placing 1,000 / 5,000 / 10,000 blocks went from 18 / 294 / 1,108 ms to 9 / 39 / 73 ms in Chromium, and its output matched the old code's on 770 placements.The user picked this design on a findings page ("Double-click a block to type at its line in the editor").
Tests: a browser test of each block kind, the caret's column, no leftover selection, selected words, a link that scrolls the preview, and a written preview; it fails without the double-click and without each guard. A runtime case holds the fence alignment.