Skip to content

fix(html): make code-tools toggle work when code-copy is enabled - #14707

Merged
cderv merged 2 commits into
quarto-dev:mainfrom
mcanouil:fix/13583-code-tools-code-copy
Jul 21, 2026
Merged

fix(html): make code-tools toggle work when code-copy is enabled#14707
cderv merged 2 commits into
quarto-dev:mainfrom
mcanouil:fix/13583-code-tools-code-copy

Conversation

@mcanouil

@mcanouil mcanouil commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

The code-copy scaffold introduced in 1.8.15 wraps each code block in a div.code-copy-outer-scaffold, which broke the "Show All Code" / "Hide All Code" handler's direct-child selectors. The menu rendered but clicks did nothing. Selectors now key off details.code-fold and div.sourceCode.cell-code, which the scaffold cannot displace.

  • Fixes the fold toggle, which matched zero elements and also mistook the scaffold for the <details>.
  • Fixes the hidden/unhidden toggle for echo: false cells under keep-hidden: true, broken the same way but not reported (found/verified during Claude's review).
  • Applies the same selector to the server-side toggle detection, which previously worked only because that post-processor happens to run before the scaffold is inserted.
  • Also picks up folded blocks with filename, and folded blocks inside tabsets, callouts and listings, which the old direct-child selector never reached.

Verified in headless Chromium by clicking both menu items on a rendered document: all folded blocks open and close together and the hidden block flips both ways. Patching the selectors back to their previous form on the same page reproduces the inert behaviour.

Closes #13583.

The code-copy scaffold added in 1.8.15 wraps each code block in a
div.code-copy-outer-scaffold, which left the "Show All Code" and
"Hide All Code" handler matching nothing: its selectors assumed
.sourceCode was a direct child of <details> and of .cell, and it
reached the <details> via .parentElement.

Key the selectors off details.code-fold and div.sourceCode.cell-code
instead, which the scaffold cannot displace. Apply the same selector
to the server-side toggle detection, which until now only worked
because that post-processor happens to run before the scaffold is
inserted.
@mcanouil mcanouil added bug Something isn't working regression Functionality that used to work but now is broken. code-blocks labels Jul 19, 2026
@mcanouil mcanouil self-assigned this Jul 19, 2026
@posit-snyk-bot

posit-snyk-bot commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cderv cderv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mcanouil.

One thing before merge: we're missing a test that actually exercises the toggle. The smoke fixture locks the DOM shape, but since this PR doesn't touch the render pipeline, the pre-fix version produces identical HTML — so the fixture passes with or without the fix. I confirmed it by reverting the two changed files to their pre-fix state and re-running the new fixture still passes green, so it wouldn't have caught the original regression.

The behavior is pure client-side JS, so it needs a Playwright test that clicks Show All Code / Hide All Code and asserts the <details> open/close and the hiddenunhidden swap on hidden cells, with code-copy enabled. I'll add that before merging.

Comment thread news/changelog-1.10.md
…rto-dev#13583)

The smoke fixture only asserts on rendered HTML, which is byte-identical
before and after this fix (the render pipeline is untouched), so it passes
on the buggy selectors too and cannot guard the behavior. This Playwright
test exercises the actual client-side JS: it clicks Show All Code / Hide All
Code and asserts every <details> opens/closes and the echo:false cell's
source swaps hidden<->unhidden, with code-copy enabled. It fails on the
pre-fix selectors (details never open) and passes on the fix. Uses an {ojs}
cell so the fixture needs no Python/R kernel.
@cderv

cderv commented Jul 21, 2026

Copy link
Copy Markdown
Member

Follow-up: added the Playwright test and pushed it to the branch.

tests/integration/playwright/tests/html-code-tools-toggle.spec.ts plus an {ojs} fixture — {ojs} so it needs no Python/R kernel while still producing the same folded + code-copy scaffold DOM. It clicks Show All Code / Hide All Code and asserts every <details> opens/closes and the echo: false cell's source swaps hiddenunhidden.

It's a real regression guard: it fails on the pre-fix code (the <details> never opens after Show All Code) and passes on this PR. I kept your smoke fixture alongside it — the two are complementary, one locks the rendered DOM contract, the other the JS behavior.

@mcanouil

Copy link
Copy Markdown
Collaborator Author

Thanks, not yet used to playwright testing.

@cderv

cderv commented Jul 21, 2026

Copy link
Copy Markdown
Member

No problem. 🤖 should know how to write them with the context present. We don't need always some playwright, but for things that impact JS usually we need to verify if the regression can be tested without in-browser behavior or not. Some times our Deno test framework can't test.

I'll merge.

Thanks again !

@mcanouil

Copy link
Copy Markdown
Collaborator Author

Claude might have caught this, unfortunately, I did it without (quite limited subscription at the moment)

@cderv
cderv merged commit 4ac7416 into quarto-dev:main Jul 21, 2026
91 of 93 checks passed
@mcanouil
mcanouil deleted the fix/13583-code-tools-code-copy branch July 21, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working code-blocks regression Functionality that used to work but now is broken.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

code-tools buttons don't work if code-copy is enabled

3 participants