Skip to content

fix: copy the correct code block #1406

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 3 commits into from
Jul 8, 2025

Conversation

wyMinLwin
Copy link
Contributor

@wyMinLwin wyMinLwin commented Jul 4, 2025

fixes #1403

Changes

/packages/site-kit/src/lib/components/Text.svelte

Problem

This issue is due to selecting wrong targeted element.

Solution

I changed query for selecting document.

parent.querySelector(`pre[data-language="${ts ? 'ts' : 'js'}"] code`) as HTMLElement;

Impact

The change improves the logic for selecting code blocks based on the language toggle by explicitly filtering for the ts or js language instead of relying on positional selectors.

Copy link

vercel bot commented Jul 4, 2025

@wyMinLwin is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@eltigerchino eltigerchino changed the title fix: Fix copy button copying wrong code for Issue #1403 fix: correctly copy the correct code block Jul 7, 2025
@eltigerchino eltigerchino changed the title fix: correctly copy the correct code block fix: copy the correct code block Jul 7, 2025
Copy link

vercel bot commented Jul 7, 2025

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

Name Status Preview Updated (UTC)
svelte-dev ✅ Ready (Inspect) Visit Preview Jul 8, 2025 3:45am

@wyMinLwin
Copy link
Contributor Author

I just rechecked and my latest commit ignored the bash command.
I fixed that in my latest commit.

Copy link
Member

@eltigerchino eltigerchino left a comment

Choose a reason for hiding this comment

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

Nice find! It was previously selecting the JS block and the last code element which was the code inside the TypeScript hover tooltip. We could try using > in the selector so it doesn't grab code blocks in tooltips in the future but the current solution works great already.

@eltigerchino eltigerchino merged commit 9956e56 into sveltejs:main Jul 8, 2025
4 checks passed
@wyMinLwin wyMinLwin deleted the fix-copy-wrong-code branch July 8, 2025 18:14
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.

[docs] Copy button pulls the wrong code sample
2 participants