Repository navigation
fix(file-viewer): find and comment on text inside fenced code blocks - #21133
Conversation
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Before merge, check that [DESIGN-REVIEWED] fac04a1 Description read[DESCRIPTION-READ] 1af98f9eaa890207ca8a9194ea92574add27168015f3fbc6b762b44455b1a887 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
UX Review (Opus 5.5, fork) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS A comment saved on code leaves no mark in the document, while prose comments are underlined, so code comments are only visible in the pending list. Watch
The screenshots show every changed element: find with no results before the fix, a find match inside code, a find spanning prose and code, the comment box over code, and the pending comment. No first-time reader has looked at them, so this lane can't go higher than CONCERNS. [UX-REVIEWED] fac04a1 Description read[DESCRIPTION-READ] ac7ffe9f968af1b113f46fa45c394a429cba063e04b813dd7d184119e059b0ee That sha256 names everything this verdict read: the PR description, plus the 9 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Before merge, check that a comment dragged over a code file's plain fallback still quotes the right line now that send quotes from Inventory (9 items) — 9 justifiedIntent: let a reader find text in a markdown preview's fenced code blocks and comment on it, as Edit mode already allows. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] fac04a1 Description read[DESCRIPTION-READ] 7cd7260423d9db36166d94219d1af85546451df0242cc2b46579b3f04b426d04 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
cruisercohen
left a comment
There was a problem hiding this comment.
Thanks @presidentarrow, this is a careful fix with a very thorough description, and thanks for the before/after evidence.
Approving on 7e76595. The cause matches #21124: Pierre draws each fenced block into an open shadow root, the find's TreeWalker never enters it, and a drag inside one reaches the document as a collapsed selection. pierreShadow.ts reads each [data-line] as one run, so a phrase can cross token spans while the gutter numbers stay out, and getComposedRanges gives the toolbar the real range.
Checked locally:
- The 4 new test files pass (73). With the 4 changed components put back to main's versions, 23 of them fail.
- The related suites (SelectionToolbar, MarkdownPanel, CommentOverlay, the find and highlight tests, artifact comments, AssistantMessage) pass: 34 files, 817 tests. eslint and
tsc -p tsconfig.app.json --noEmitare clean. - Edge cases I looked at: the global regex starts each run at index 0, because a failed
execresetslastIndex. The find paints through CSS highlights, sowatchText's observer cannot fire on its own repaint. A multi-line drag stays inside the content column, so it does not pick up line numbers. The code-selection path is opt-in for the file panel's preview only, and the diff view keeps ignoring such a drag.
The UX lane's two notes (no underline for a comment on code, and no box over code in browsers without getComposedRanges) are both covered by your Not-a-goal list and the conventions doc, so they read to me as follow-ups.
I approved the waiting workflow runs, as you asked, and re-ran Cross-Platform Portability once after it timed out during checkout. Approving on the code; CI still running at 10:26 PDT: 85 checks pass, none failed, and two backend test shards and PR Readiness are still pending.
|
UX note "A comment on code leaves no mark in the document" (span=236a366bb012): not changed in this PR. It is listed under "Not a goal" in the description: the comment is saved with its quote, and only the paint in the document is missing. The skip is deliberate. Painting a mark inside a fenced block needs an anchor that survives Pierre swapping in the highlighted copy of the block, so it is a design of its own. The approving review reads this note as a follow-up. I can open an issue for it if you want one. |
|
Browser coverage, raised by three lanes: UX ("In older browsers, dragging over code does nothing and says nothing", span=889476718201), Design (check in Safari 17.x that the older Covered: Not covered: I did not run a real Safari 17.x or Firefox, as the description says under "Not checked". A notice for older browsers would be a new surface outside this PR's goal, and the approving review reads the missing-box note as a follow-up. |
|
Opus finding (span=62c33351e01e): the stored column of a code comment lands on leading whitespace. Confirmed, and not changed in this PR. In The fix is two lines and one test. A push may dismiss the approval on 7e76595 and would likely send the fork workflows back to waiting for approval, so I held it. @cruisercohen, default: merge as is and take the column fix as a follow-up. Say if you want it pushed in this PR instead. |
|
@cruisercohen thanks again for the approval. PR Readiness passed at 17:42 UTC and there are 104 checks, none failing. GitHub shows UNSTABLE only because the Sensitive Change Review run created by your approval is waiting for approval; it is the one check suite that is not green. Could you merge when you have a moment? |
iamwhatever
left a comment
There was a problem hiding this comment.
Requesting changes on 7e76595. The code looks sound, but two follow-ups are deferred and neither has a linked issue.
The fix is right: Pierre draws fenced blocks into shadow roots, and pierreShadow.ts now reads each [data-line] as one run and resolves drags with getComposedRanges. When that API is missing, throws or returns a range outside one shown block, the code returns null, and the code-selection path is opt-in for the file panel preview only. CI on this head is green, and every lane item has a reply.
Deferred items that need an issue (or a fix in this PR):
- A comment on code leaves no mark in the document, because the underline pass skips
inCodecomments (MarkdownPanel.tsx#L846). The UX lane asked to track it, and your reply offers an issue. - Opus span=62c33351e01e: a drag that starts on a space stores the column of that space, because the untrimmed
rawis thefindCoordsneedle (MarkdownPanel.tsx#L524). You confirmed it and held the fix.
To clear this, either push the column fix with its test, or open one issue per remaining item and link each in the PR description. A new push needs a fresh review.
— crew-pr-reviewer (r110)
|
@cruisercohen the crew reviewer's request for changes is what keeps this PR blocked. It asks for a fix or a tracking issue for the two items I had deferred, so I filed one issue for each:
I did not push the column fix, because a push would dismiss your approval on |
|
@presidentarrow Thanks for filing #21837 and #21838. We won't dismiss iamwhatever's review: clearing a maintainer's change request is his call. His review also asks for each issue to be linked in the PR description, and the description's Related Issues section still lists only #21124. Once both are linked there, his re-review is the next step. Our approval on 7e76595 stands. |
|
@cruisercohen both issues are now listed under Related Issues as @iamwhatever that covers the two items in your review. The edit queued five workflow runs (Code Review, Issue Gate, GPT 6.1 Review, Sensitive Change Review and Screenshot Evidence) that are waiting for approval. |
35d291b to
fac04a1
Compare
|
Pushed fac04a1. Against 35d291b the change is one new test file, The commit is also rebased onto GPT 6.1 and Opus 5.5 reported no findings on 35d291b. Design, First Principles and UX reported CONCERNS; each item has its own comment below. The push re-queued the fork workflows: 19 runs are waiting for approval. The last round was approved at 10:01 UTC, and I would be grateful if a maintainer could approve this one too. |
|
Design Watch "No test renders real Pierre" (span=ff29fa39146b) on 35d291b: fixed in fac04a1. The lane was right: every fixture was built by hand in
I broke
The test runs in about 2.5 s per case because the block is shown at WarmSwap's 2.5 s deadline ( I did not snapshot Pierre's markup, so a harmless upgrade stays green. |
|
Design suggestion "a host-supplied resolver" (span=05d12f795e0c) on 35d291b: the same suggestion as span 312b93bd2a6b on b05066d, and my answer is the one in the comment above (issuecomment-6288243128): not taken in this PR. In short, |
|
UX Watch "Older browsers fail silently" (span=d4316b141d1d) on 35d291b: the same item as span ccbc741e23aa on b05066d, and the question I put there is still open (issuecomment-6288245416): do the reviewers want a hint for browsers without The lane adds that the Tip banner "Select any text to add inline comments" promises something that will not happen there. The string is |
|
UX Watch "This lane had no blind read" (span=616ca1f4325f) on 35d291b: nothing in the diff changes this. The lane read attachments 01–06 and wants a first-time reader to look at the find highlight in code, the comment box over code and the pending code comment. I can supply the screenshots, which are in the description, but not the reader. If a reviewer is willing to open the preview on a markdown file with a fenced block and say what they expect to happen, I will act on it. |
|
UX Watch "A code comment leaves no mark in the document" (span=ed1e9d57c632) on 35d291b: the same item as span c14381723c7b on b05066d and span bc280d3d06dc before it. Out of this PR's goal: |
|
First Principles "Not justified as shipped", item 6 (span=648bdfbdd35f) on 35d291b: kept, for the reasons in the comment on the same item at b05066d (issuecomment-6288243175, span 152729680649): the shared slot is the state the GPT 6.1 lane blocked, with a reproduction (span 23dbf0c7f905), and a blocking lane outranks an advisory one. A reviewer who wants per-passage drafts dropped is amending the Goal, which the lane names as what clears this item ("a human amends the Goal"); I will do it if asked. One correction to the lane's evidence. It cites GPT 6.1 and Opus 5.5 reported no findings on this head, so the draft-key fix for the long-row finding is accepted by both. |
|
First Principles "Not justified as shipped", item 7 (span=8ec347be9115) on 35d291b: it goes or stays with item 6, and the lane says so ("the only reader is the item 6 key"). I checked that claim: the only places that name |
|
UX Watch "Repeated commands get no location" (span=c7922df0aba2) on fac04a1: the behaviour is as the lane reads it, it is listed under What the code does. The lane is also right that nothing in the UI says so. The pending row ( Question for the reviewers: do you want a "(location unknown)" marker on that row in this PR? It needs a catalog key in every locale and a decision on its wording, and |
|
UX Watch "Code comments leave no trace in the file" (span=3a7cc0a02b71) on fac04a1: the same item as span ed1e9d57c632 on 35d291b, c14381723c7b on b05066d and bc280d3d06dc before it, and my answer has not changed: out of this PR's goal ( The lane closes this item with "a human should accept that gap knowingly before merging". That acceptance is for the maintainers; I have not asked for it beyond this comment, and I have changed nothing for it. |
|
Design Review (PASS) check "that This is the same check as r113 item 1, answered in issuecomment-6281680047. So a preview that changes every frame with find open would keep the main thread about 57% busy. I used a synthetic mutation source, not a streaming file, so I am calling the bound acceptable for a preview and not measured for every source. If the reviewers want a cheaper bound (for example debouncing the re-find while a source is streaming), say so and I will add it with a test. |
|
First Principles (PASS) check "that a comment dragged over a code file's plain fallback still quotes the right line now that send quotes from
I checked that they can fail. With |
cruisercohen
left a comment
There was a problem hiding this comment.
Re-reviewed fac04a1. Approving.
- The column-100,000 aliasing is fixed (in 35d291b; fac04a1 leaves that code byte-identical).
packedCodePositionrefuses a column at or past 100,000, a row at or past 10,000,000, and a packed number that is not a safe integer, so those passages take the shared fallback slot instead of another passage's key. With the repro from the finding (a 100,000-character row followed bytarget, thentargeton the next row), the firsttargetnow gets no position and the second keeps 200000, in both the highlighted and the plain copy. On b05066d both got 200000. Each clause fails its own tests when I remove it: the column check fails 4 (3 in pierreShadow, 1 in SelectionToolbar), the row check 1, and the safe-integer check 1. - The two-file fix from b05066d is intact: going back to counting the whole
.diff-blockstill fails the same 4 tests. - The new real-Pierre test answers Design's note: renaming the row selector in
pierreShadow.tsfails 2 of its 3 tests, as you described. - Locally, tsc, eslint and
i18n:checkare clean, the PR's 8 test files pass (223 tests), and 164 related test files passed on 35d291b (2,855 tests). GPT 6.1 and Opus 5.5 report no blocking findings, and every CI check on this head passes. - On the older-browser hint: I would not add it in this PR. On those browsers the box behaves as it did before this change, so nothing regresses, few users are on those versions, and the hint would be a new string in every locale.
frontend-conventions.mdalready records the limit.
|
UX Watch "Older browsers fail silently" (spans ccbc741e23aa on b05066d and d4316b141d1d on 35d291b): not adding the hint, as cruisercohen's review of fac04a1 (12:55 UTC) says: the box behaves on those browsers as it did before this change, so nothing regresses, few users are on them, and the hint would be a new string in every locale. Still open, and not acted on: whether a "(location unknown)" marker is wanted on a pending comment whose first row repeats in the file (issuecomment-6290400589), and whether |
|
PR #21133 has everything it needs except one review decision.
Could one of you dismiss that review, or ask it to re-review, and then merge? The open items left are advisory questions to the reviewers, listed in the what-is-left note (comment 6275056217). |
iamwhatever
left a comment
There was a problem hiding this comment.
APPROVE at fac04a1. This replaces our r110 change request.
Both r113 items are answered. Draft keys now count the .code-block / [data-diff-section] unit, which is always present, so toggling plain diffs no longer shifts a later fence's key (pierreShadow.ts L99-L105). The watchText cost is measured and bounded to one re-find per frame. Find paints through CSS.highlights, so a re-find never mutates the DOM it watches.
Every current-head lane item has its own reply. The missing mark on a code comment is tracked in #21837. On your open question: a "(location unknown)" marker is not needed for this PR, because the comment still carries its quote and the limit is stated under Not a goal. CI is green, and cruisercohen approved this head.
— crew-pr-reviewer (r115)
Problem / Motivation
Goal: In a markdown file's preview, Cmd/Ctrl+F finds text inside fenced code blocks, and selecting that text opens the comment box.
Open a markdown file that has a fenced block, press Cmd/Ctrl+F and search for a command that appears only inside the block: the bar says "No results". Drag over the same text and no comment box appears, so the block cannot be commented on. Edit mode already works.
Why it matters
READMEs, runbooks and skills keep their commands in fenced blocks, so those are the strings people search for and want to comment on. Today they have to switch to Edit mode to find one, and cannot comment on one at all.
Not a goal
AssistantMessagehas the same gap and its own search.codeSelection, so they behave as before. The artifact pages' comment anchors cannot resolve a drag inside a code block, and the chat has no comment box.SelectionToolbartakes such a drag only from a host that passescodeSelection, and only the file panel's preview does.data-sourcepos, so that comment keeps its quote and carries no line.What changed (motivation → approach → change)
Find and the comment box work inside fenced code blocks in the preview. They did not before, because Pierre, the code renderer, draws each fenced block into an open shadow root, and two things stop at it. The find's
TreeWalkernever enters a shadow root. A drag inside one reaches the document as a collapsed selection (both ends move to the host's parent), whichSelectionToolbardrops as empty.utils/pierreShadow.tsreads a block one source line at a time, so a phrase can cross Pierre's token spans, and it skips the line numbers beside the code. It resolves a drag withSelection.getComposedRanges. The find (useMarkdownPanelFind.ts) matches through it.SelectionToolbar.tsxuses it to open the box for a host that passescodeSelection(the file panel's preview does; its diff view, the artifact pages and the chat do not), andMarkdownPanel.tsxto anchor the comment and to quote its line, counted in the file's own text and not in the fenced copy the preview draws of a code file. The comment carriesinCode(InlineCommentinCommentOverlay.tsx) so it is not underlined on the first matching prose, and a line and column only when the first row of the selection can be told apart from every other copy of it in the file.findUniqueCoords(markdownPanelSourcePos.ts) looks up only that row, so a block inside a list or quote still gets a position, and it reports the column of the first visible character, so the indentation a drag started on does not shift it. A comment draft is filed under the position of the passage's first visible character: which code block it is in (adifffence counts once per file, each marked byDiffBlock.tsx), then the row's own line number and the column in it (codePassagePositioninpierreShadow.ts, negated so it never meets a prose offset). A block still drawn as its plain copy gives the key its highlighted copy gives, so a draft typed before the swap is found after it. The key does not depend on which blocks have painted, whether adifffence holds a Pierre host, or which rows the page holds, so the same command in two blocks keeps two drafts. A column or row that does not fit its field (a line of 100,000 characters) takes the shared fallback slot, which no placed passage uses. The box follows scroll through the live range.website/docs/frontend-conventions.mdrecords which browsers each half needs.A find survives Pierre's late swap of a block.
WarmSwapshows a plain copy first, parks the highlighted copy beside it, then swaps them, which left a find holding ranges on nodes that were gone. The find skips the parked copy (its text would count twice), andwatchTextfinds again on the highlighted copy after the swap, on the same match and without scrolling the reader. The current find match in a code or diff block takes one dark text colour (highlights-and-page-zoom.css), since Pierre's token colours disappear on the orange fill; prose is unchanged.Backwards compatibility
Compatible: nothing accepted before is rejected;
InlineCommentgains an optionalinCode, so saved drafts load as before.Removes nothing: every prose match and selection behaves as before, and every other
SelectionToolbarhost behaves as before because the code-selection path is opt-in.Tests
utils/pierreShadow.test.tsdifffence counted as its own block, with or without its host; a plain copy of a fence gives the key its highlighted copy gives; a column, row or block count that does not fit its field gives no position, in the plain copy and the highlighted onetest/useMarkdownPanelFind.test.tsxtest/SelectionToolbar.codeBlock.test.tsxtest/CommentOverlay.test.tsfindUniqueCoords: the first visible character of an indented selection, a selection that starts on a newline, CRLF files, blocks in a list or quote, and no position for a first row another copy shares or for absent texttest/MarkdownPanelCodeBlock.test.tsxinCode, carries the line and column of its first row only when that row can be told apart from other copies, and is not underlined in prose; a code file's comment quotes its own line when sent, from the highlighted copy or the plain fallback; the diff view opens no box in the side panel or in full screentest/DiffBlock.test.tsxtest/findCurrentMatchContrast.test.tsTests are 2,448 of the 2,890 changed lines. The eight files this PR adds or extends pass in five shuffled orders (seeds 11, 23, 47, 91, 2026). Each production edit was broken one line at a time (129 scripted mutations): 128 turned a test red, and the other is equivalent (it hands
findUniqueCoordsthe trimmed selection, which it trims again).Manual verification
Chromium, against a gateway built from this branch, on a generic markdown file:
mainat0a008292c9: a phrase from the prose gives "1 of 1", whilenpm run build, which sits only in a fence, gives "No results". A drag over it opens no box.npm run build, which sits only in a fence: "1 of 1", and the painted range is exactly that text.docker build, once in prose and once in a fence below the fold: Enter steps to the second. That block is still a plain copy when it is reached, then Pierre swaps it in. The bar keeps "2 of 2" and the match stays painted.npm run build: the box opens, Copy putsnpm run buildon the clipboard, Add comment lists the comment with its quote.difffence ahead of three identical code fences, a draft typed on the second, then plain diffs turned on and a reload, is not offered on the third.mycli rm NAME --forcein a plain copy comes back over the highlighted copy after a fresh load, the text typed there comes back over the plain copy, and the same passage in the second block opens empty. Scrolling the panel by 120 px moves a box opened over a highlighted copy, or over a plain copy that stays plain, by 120 px; a box opened over a plain copy that then swaps does not move.difffence of two files that share a first line: a draft typed on that line in file one is not offered in file two after a reload, the two drafts are stored apart, and file one's comes back. The code fence after it opens empty.Not checked: Firefox and Safari.
Screenshots / video
Before, on
main: the command in the fence gives "No results".After: the same search finds it.
Stepping to a fence below the fold, after Pierre swapped it in:
The drag before and after, the comment box over code, and the comment added
Related Issues
Closes #21124
Closes #21838
Refs #21837 (the underline for a comment on code, listed under Not a goal)
Pattern harvest
Rule candidate: agents-md
Pattern: a
TreeWalkerorSelectionread over a subtree that can hold a Pierre block stops at its shadow root; read it throughutils/pierreShadow.ts.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)