Skip to content

Fix code copy button covering code annotation marker - #15136

Open
cderv wants to merge 4 commits into
mainfrom
fix/issue-13444
Open

cderv wants to merge 4 commits into
mainfrom
fix/issue-13444

Conversation

@cderv

@cderv cderv commented Oct 21, 2026

Copy link
Copy Markdown
Member

Since #13024 wrapped the code copy button in div.code-copy-outer-scaffold (first released in v1.8.15), the button no longer sits inside the pre.
The rule that moved it clear of the annotation gutter, .code-annotated .code-copy-button, still targets a descendant of pre.code-annotated, so it matches nothing.
On an annotated block the button lands on top of the marker on the first line, and the annotation can no longer be opened by hover or click.

Fix

The selector now follows the scaffold: .code-copy-outer-scaffold:has(pre.code-annotated) > .code-copy-button.
The scaffold itself stays, as it is what keeps the button from scrolling with the code and lets line numbers work (#13009, #5538).
The rule is based on the one suggested in the issue thread.

The old 1.25em margin worked in 1.7 because the button sat inside the pre and inherited the code font size.
The button now has the body font size, while the gutter is calc(20px + 0.5em) in the code font size.
The rule therefore sets font-size: $code-block-font-size on the button, so margin-right: calc(20px + 0.5em + 5px) is the gutter width plus the button's usual 5px for any theme font size.
It is written with em rather than 0.5 * $code-block-font-size, because a percentage value such as 75% would resolve against the container width inside margin and push the button far into the code.

Annotated blocks inside callouts are still wrong, which is separate and tracked in #13446.
No backport is planned: the regression is from v1.8.15 and the stable release is v1.10.

Fixes #13444

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog in the PR
  • ensured the present test suite passes
  • added new tests
  • created a separate documentation PR in Quarto's website repo and linked it to this PR
AI-assisted PR
  • AI tool used: Claude Code
  • Codebase grounding: local clone, DeepWiki MCP
  • Human review: I have reviewed, tested, and verified the AI-generated content before submitting.

Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.

cderv added 4 commits October 21, 2026 16:55
Since the code-copy scaffold moved the copy button out of the pre,
the rule that shifted it clear of the annotation gutter no longer
matches, so the button sits on top of the marker and swallows its
hover. The test checks that the marker is the element under its own
center and that the annotation tooltip opens. It fails in chromium,
firefox and webkit until the CSS is fixed.

Refs #13444
Since the copy button moved out of the pre into the outer scaffold, the
rule that shifted it left of the annotation gutter matched nothing, so
the button sat on top of the marker of an annotated first line and
swallowed its hover or click. The scaffold stays: it keeps the button
from scrolling with the code while line numbers need visible overflow.

The rule now targets the button through the scaffold that holds an
annotated pre. Its margin can no longer be 1.25em: that relied on the
button inheriting the code font size, and as a sibling of div.sourceCode
its em is now the body size. The margin is the gutter width,
calc(20px + 0.5em) in code font size, rewritten as 0.5 times
$code-block-font-size so it holds when a theme changes that size, plus
the default 5px. The button and the pre resolve em from the same
parent, so the two stay in step.

The test now also covers select mode, a theme with a 0.75em code block
font size, and checks that the button of a block without annotations
keeps its default position.

Fixes #13444
The fix is not backported to v1.10, and on main the Regression fixes
section marks entries that are.
The margin multiplied $code-block-font-size inside calc(), which only
matches the gutter for length units. A percentage, which a theme or a
brand typography size can set, resolved against the scaffold width in
a margin, and pushed the button about 290px into the code.

The button now takes the code block font size itself, so it shares the
pre's em, and the margin repeats the gutter's own calc(20px + 0.5em)
plus 5px. That holds for any value the pre accepts. The copy icon is
sized in rem, so it keeps its size.
@posit-snyk-bot

posit-snyk-bot commented Oct 21, 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 added this pull request to stack #15142 October 22, 2026 09:10
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.

Code-copy button overlaps with code-annotation marker

2 participants