Skip to content

fix(rendering): prevent copy button from scrolling with code block content#5118

Open
HUQIANTAO wants to merge 1 commit into
esengine:main-v2from
HUQIANTAO:fix/code-block-copy-button-scroll
Open

fix(rendering): prevent copy button from scrolling with code block content#5118
HUQIANTAO wants to merge 1 commit into
esengine:main-v2from
HUQIANTAO:fix/code-block-copy-button-scroll

Conversation

@HUQIANTAO

Copy link
Copy Markdown
Contributor

Problem

When a code block contains long lines that trigger horizontal scrolling, the copy button in the top-right corner drifts off-screen with the content instead of staying pinned to the visible area.

Reproduction (Issue #5096):

  1. Open a conversation with a code block containing long lines
  2. Scroll the code block horizontally
  3. The copy button moves with the content, disappearing off the right edge

Root Cause

The DOM structure is:

div.code-block          (position: relative)
  button.code-block__copy   (position: absolute, top: 7px, right: 7px)
  pre.code                  (overflow: auto, max-height: 360px)
    code

The .code-block wrapper has position: relative but no explicit width constraint. When the inner <pre> overflows horizontally, the wrapper expands to match the full scroll width. The absolutely-positioned copy button is then anchored to the right edge of this expanded container — which is off-screen.

Fix

Add overflow: hidden to .code-block. This constrains the wrapper to its parent's width, so the absolutely-positioned button stays pinned at the top-right corner of the visible area. The inner <pre> retains its own overflow: auto for independent scrolling.

Single-line change in desktop/frontend/src/styles.css:

.code-block {
  position: relative;
+ overflow: hidden;
}

Testing

  • Verify copy button remains visible at top-right when scrolling code blocks horizontally
  • Verify vertical scrolling within code blocks still works
  • Verify copy button still appears on hover and copy functionality works

…ntent

The copy button in code blocks uses position: absolute relative to the
.code-block wrapper. When the inner <pre> overflows horizontally, the
wrapper expands to fit the full scroll width, causing the button to
drift off-screen with the content.

Adding overflow: hidden to .code-block constrains the wrapper to its
parent's width so the absolutely-positioned button stays pinned at the
top-right corner of the visible area. The inner <pre> retains its own
overflow: auto for independent scrolling.

Fixes esengine#5096
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant