Skip to content

feat: Add copy button to highlighted code lines #12983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 28, 2025

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Mar 12, 2025

This PR adds a copy to clipboard button for highlighted line groups within a code block.

Why? In larger code examples, I find the main copy to clipboard button impractical because it copies a lot of code that's already there. So most of the time, it's unusable for me, making me have to highlight and select the appropriate code parts anyway. Since we can highlight the important code parts, this has already gotten much easier. But I think we can go a step further and offer the same, nice copy UX, just on a finer granularity.

Anyone have ideas how to test this best? Happy to learn!

Demo:

Screen.Recording.2025-03-12.at.15.43.44.mov

Update: new copy feedback:

Screen.Recording.2025-03-28.at.12.14.43.mov

Copy link

vercel bot commented Mar 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
develop-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 28, 2025 11:57am
sentry-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 28, 2025 11:57am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
changelog ⬜️ Ignored (Inspect) Visit Preview Mar 28, 2025 11:57am

Copy link

codecov bot commented Mar 12, 2025

Bundle Report

Changes will increase total bundle size by 6.25kB (0.03%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sentry-docs-server-cjs 10.6MB 3.02kB (0.03%) ⬆️
sentry-docs-client-array-push 9.44MB 3.23kB (0.03%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: sentry-docs-client-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
static/chunks/pages/_app-*.js -3 bytes 869.55kB -0.0%
static/css/*.css -122 bytes 18.55kB -0.65%
static/chunks/4612-*.js -3 bytes 398.04kB -0.0%
static/chunks/4335-*.js (New) 247.57kB 247.57kB 100.0% 🚀
static/chunks/app/[[...path]]/page-*.js 2.21kB 77.75kB 2.93%
static/chunks/6716.*.js (New) 71.94kB 71.94kB 100.0% 🚀
server/middleware-*.js -5.55kB 1.0kB -84.74%
server/middleware-*.js 5.55kB 6.55kB 555.3% ⚠️
static/1qRGby_8u3irT4pTrW3ij/_buildManifest.js (New) 578 bytes 578 bytes 100.0% 🚀
static/1qRGby_8u3irT4pTrW3ij/_ssgManifest.js (New) 77 bytes 77 bytes 100.0% 🚀
static/chunks/5075-*.js (Deleted) -246.42kB 0 bytes -100.0% 🗑️
static/chunks/4335.*.js (Deleted) -71.94kB 0 bytes -100.0% 🗑️
static/YrPdcrB410pBVtXjW3Aow/_buildManifest.js (Deleted) -578 bytes 0 bytes -100.0% 🗑️
static/YrPdcrB410pBVtXjW3Aow/_ssgManifest.js (Deleted) -77 bytes 0 bytes -100.0% 🗑️

Files in static/chunks/app/[[...path]]/page-*.js:

  • ./src/components/codeBlock/code-blocks.module.scss → Total Size: 309 bytes
view changes for bundle: sentry-docs-server-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
1729.js -3 bytes 1.58MB -0.0%
../instrumentation.js -3 bytes 910.48kB -0.0%
9523.js -3 bytes 886.53kB -0.0%
../app/[[...path]]/page.js 3.03kB 538.85kB 0.56%

Files in ../app/[[...path]]/page.js:

  • ./src/components/codeBlock/index.tsx → Total Size: 1.3kB

  • ./src/components/codeBlock/code-blocks.module.scss → Total Size: 300 bytes

App Routes Affected:

App Route Size Change Total Size Change (%)
/[[...path]] 3.03kB 3.09MB 0.1%

Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

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

Just noticed a slight change in UI here: bc the icon takes a bit more space the line itself takes more space and the red marker on the side does not scale with it
Screenshot 2025-03-24 at 09 50 57

Other than that :shipit:, thank you!

@Lms24
Copy link
Member Author

Lms24 commented Mar 28, 2025

Just noticed a slight change in UI here: bc the icon takes a bit more space the line itself takes more space and the red marker on the side does not scale with it

Ah so, this was somewhat on purpose but I forgot to mention it: I added a bit of vertical padding because single-line highlights seemed too narrow, especially with the new button. If you're fine with it, I'll keep the padding but ensure that the red marker scales to the entire highlight block. Once that's done, I'll merge it but we can revisit the styling in a new PR. I got some feedback that we should change the color of the red marker anyway, so we could then tackle it in the same PR :)

@Lms24 Lms24 force-pushed the lms/feat-copy-highlighted-code-blocks branch from 7ae03b3 to ce4afb4 Compare March 28, 2025 11:27
@Lms24 Lms24 merged commit 263cc3f into master Mar 28, 2025
13 checks passed
@Lms24 Lms24 deleted the lms/feat-copy-highlighted-code-blocks branch March 28, 2025 13:51
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants