Skip to content

fix(scss): code annotation line highlight overflow - #13429

Merged
cderv merged 9 commits into
quarto-dev:mainfrom
mcanouil:fix/code-annotation-highlight-overflow
Oct 28, 2026
Merged

cderv merged 9 commits into
quarto-dev:mainfrom
mcanouil:fix/code-annotation-highlight-overflow

Conversation

@mcanouil

@mcanouil mcanouil commented Sep 26, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Since v1.8.15, selecting a code annotation draws a highlight band that spills out to the left of the code block and sits above the gutter band.

The script placed the bands from offsetTop, which is relative to the code element, but each band is positioned against a different containing block.
In dashboards the band sat about 20 px too high.
In Reveal.js a negative margin pushed it off the slide.

Both bands are now placed from the line positions, converted to the CSS pixels of their own container, since Reveal.js scales slides.
The band spans the code block, line numbers included, even with code-copy: false.

Format Before After
html In an HTML page on main, the highlight band on line 3 extends past the left edge of the code block. In an HTML page with this change, the highlight band on line 3 stays inside the code block and lines up with the gutter band.
dashboard In a dashboard on main, the highlight band covers line 2 while the selected annotation marker is on line 3. In a dashboard with this change, the highlight band covers line 3, next to its annotation marker.
revealjs On a Reveal.js slide on main, the highlight band on line 3 is taller than the line and cuts into line 4. On a Reveal.js slide with this change, the highlight band fits line 3 and lines up with the gutter band.

New Playwright tests measure the bands against the code block and the annotated lines in html, dashboard and revealjs, with and without line numbers.
They fail on main and pass in Chromium, Firefox and WebKit.

One gap remains.
In the light arrow theme the band tint lowers the contrast of .im tokens to 4.24:1.
This predates the change and is related to #14959, so the light-theme axe test is skipped with a note.

Closes #13448

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
  • 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.

@mcanouil mcanouil self-assigned this Sep 26, 2025
@posit-snyk-bot

posit-snyk-bot commented Sep 26, 2025 •

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.

@mcanouil
mcanouil marked this pull request as ready for review September 26, 2025 09:47
mcanouil added a commit to mcanouil/quarto-mcanouil that referenced this pull request Sep 26, 2025
@mcanouil mcanouil changed the title fix: code annotation line highlight overflow fix(scss): code annotation line highlight overflow Sep 26, 2025
@cscheid

cscheid commented Sep 26, 2025

Copy link
Copy Markdown
Member

This is a CSS change. CSS changes are scary, and we need stronger assurances of the before-after behavior; we don't have good regression protection here.

Have you tested the following?

  • website with no sidebars
  • dashboards

@mcanouil

This comment has been minimized.

@cscheid

cscheid commented Sep 26, 2025

Copy link
Copy Markdown
Member

Thanks for the screenshots! They are very encouraging.

I think this change is because of the change of the DOM for the copy button.

If that's the case, then we should be treating this as a regression, and hotfix 1.8. Do I understand this right?

@mcanouil

This comment has been minimized.

@mcanouil

This comment has been minimized.

@cderv

cderv commented Sep 26, 2025 •

Copy link
Copy Markdown
Member

So basically the change is removing these rules

  margin-left: -4em;
  width: calc(100% + 4em);

and using the same as the #code-annotation-line-highlight-gutter

It looks scary to have this impact, and it raises a question for me about the underlying DOM change—as if gutter was not useful anymore.

Also I am seeing those rules are set in revealjs too... Is it impacted too?

.reveal #code-annotation-line-highlight-gutter {
width: 100%;
border-top: solid var(--quarto-hl-co-color) 1px;
border-bottom: solid var(--quarto-hl-co-color) 1px;
z-index: 2;
}
.reveal #code-annotation-line-highlight {
margin-left: -8em;
width: calc(100% + 4em);
border-top: solid var(--quarto-hl-co-color) 1px;
border-bottom: solid var(--quarto-hl-co-color) 1px;
z-index: 2;
margin-bottom: -2px;
}

is this the change with the scafold for code copy button that impact this?

Sorry for all those question - this just warns in my head when I see CSS fix only - always wondered if we missed something in our after body processing that does post process in client or in our HTML post processor... hard to know... 🤔

@mcanouil

This comment has been minimized.

@mcanouil

This comment has been minimized.

@mcanouil

This comment has been minimized.

@mcanouil

This comment has been minimized.

@cscheid

cscheid commented Sep 26, 2025

Copy link
Copy Markdown
Member

I think an in-depth follow up on the copy-button change is really needed as many things are not right now regarding code blocks/cells.

Let's do our best to be concrete here: "many things" and "not right" are not helpful terms to get us from here to there.

@mcanouil

This comment has been minimized.

@mcanouil
mcanouil marked this pull request as draft January 15, 2026 11:59
@cscheid cscheid added this to the v1.10 milestone Feb 17, 2026
@mcanouil mcanouil modified the milestones: v1.10, v1.11 Jul 30, 2026
@mcanouil
mcanouil force-pushed the fix/code-annotation-highlight-overflow branch from f818af8 to 97d09d6 Compare October 26, 2026 16:14
@mcanouil
mcanouil marked this pull request as ready for review October 26, 2026 16:14
The band and the gutter band were placed from offsetTop, which is relative
to the code element, but each band is positioned against another
containing block. In dashboards the band sat above its lines, and in
Reveal.js a negative margin pushed it out of the slide.
@mcanouil
mcanouil force-pushed the fix/code-annotation-highlight-overflow branch from 97d09d6 to b72c021 Compare October 26, 2026 16:35

@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 for reworking this!

I'll push a small adjustment before merging, so no need to push on your side meanwhile.

cderv added 3 commits October 28, 2026 12:28
…ghlight

The band is placed from client rects relative to its offsetParent. When
that offsetParent is a positioned element that scrolls, which happens
with code-copy: false, the rect difference already includes the scroll,
and setting it as an absolute offset applies it a second time, so the
band sat above its lines by the scroll offset. Adding the container's
scrollTop and scrollLeft places it back on the lines. A new Playwright
case selects an annotation inside a scrolled positioned box.

The light theme contrast test switches from test.fixme to test.fail so
it keeps running and flags when the arrow theme contrast gap (quarto-dev#14959)
is resolved, as the Playwright test conventions ask for known failures.
Reveal.js turns code-line-numbers on by default, so the slide meant to
cover code without line numbers rendered numbered code too, and both
slides exercised the same layout. Setting code-line-numbers="false" on
that block restores the unnumbered case.
The Reveal.js slide meant for unnumbered code rendered numbered code,
because Reveal.js turns code-line-numbers on by default, and the band
geometry checks pass either way. Each case now checks whether its code
block carries number-lines before measuring, so a fixture that drifts
from its label fails instead of silently covering the wrong layout.
@cderv
cderv merged commit 364ee3b into quarto-dev:main Oct 28, 2026
52 checks passed
@mcanouil
mcanouil deleted the fix/code-annotation-highlight-overflow branch October 28, 2026 13:33
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 annotation line highlight overflow and gutter miss-alignment

4 participants