Skip to content

Commit afe4f5e

Browse files
committed
fix(docs) copy elements
1 parent d435ad4 commit afe4f5e

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/components/codeBlock/code-blocks.module.scss

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
border-radius: 0 0 6px 6px;
99
margin-top: 0;
1010
margin-bottom: 0;
11-
/* Wrap overly long lines so blocks never expand layout */
12-
white-space: pre-wrap;
13-
word-break: break-word;
14-
overflow-wrap: anywhere;
11+
/* Use horizontal scroll instead of wrapping */
12+
white-space: pre;
13+
overflow-x: auto;
1514
max-width: 100%;
1615
tab-size: 2;
1716
}
@@ -26,10 +25,9 @@
2625
border: 1px solid var(--accent-11);
2726
border-radius: 6px;
2827
margin: 0;
29-
/* Ensure syntax-highlighted pre behaves like above */
30-
white-space: pre-wrap;
31-
word-break: break-word;
32-
overflow-wrap: anywhere;
28+
/* Use horizontal scroll instead of wrapping */
29+
white-space: pre;
30+
overflow-x: auto;
3331
}
3432

3533
/**
@@ -76,10 +74,8 @@
7674
float: left;
7775
min-width: 100%;
7876
box-sizing: border-box;
79-
/* Allow wrapping inside each highlighted line */
80-
white-space: pre-wrap;
81-
word-break: break-word;
82-
overflow-wrap: anywhere;
77+
/* Use horizontal scroll instead of wrapping */
78+
white-space: pre;
8379
// Set placeholder for highlight accent border color to transparent
8480
border-left: 4px solid rgba(0, 0, 0, 0);
8581

src/components/codeBlock/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ function getCopiableText(element: HTMLDivElement) {
2525
let text = '';
2626
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, {
2727
acceptNode: function (node) {
28-
// Skip if parent has .no-copy class
29-
if (node.parentElement?.classList.contains('no-copy')) {
30-
return NodeFilter.FILTER_REJECT;
28+
let parent = node.parentElement;
29+
// Walk up the tree to check if any parent has .no-copy, .hidden, or data-onboarding-option-hidden
30+
while (parent && parent !== element) {
31+
if (
32+
parent.classList.contains('no-copy') ||
33+
parent.classList.contains('hidden') ||
34+
(parent as HTMLElement).dataset?.onboardingOptionHidden
35+
) {
36+
return NodeFilter.FILTER_REJECT;
37+
}
38+
parent = parent.parentElement;
3139
}
3240
return NodeFilter.FILTER_ACCEPT;
3341
},

0 commit comments

Comments
 (0)