Skip to content

Commit 21cef6a

Browse files
dcramerclaude
andcommitted
fix(docs): Copy button now copies only visible text in terminal blocks
The copy button in package manager tabs was copying all commands (npm, pnpm, bun) instead of just the selected one. Changed getVisibleText to recursively walk the DOM and skip elements with display: none. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 58b6ae6 commit 21cef6a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

docs/src/components/Terminal.astro

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,21 @@ const { title, showCopy = false } = Astro.props;
4141
if (!button || !body) return;
4242

4343
button.addEventListener('click', async () => {
44-
// Extract text content from the terminal body
45-
const content = body.textContent || '';
44+
// Get only visible text content (respects display: none)
45+
function getVisibleText(element: Element): string {
46+
if (getComputedStyle(element).display === 'none') return '';
47+
let text = '';
48+
for (const node of element.childNodes) {
49+
if (node.nodeType === Node.TEXT_NODE) {
50+
text += node.textContent;
51+
} else if (node.nodeType === Node.ELEMENT_NODE) {
52+
text += getVisibleText(node as Element);
53+
}
54+
}
55+
return text;
56+
}
57+
58+
const content = getVisibleText(body);
4659

4760
// Split into lines and process each line
4861
const lines = content.split('\n');

0 commit comments

Comments
 (0)