Skip to content

Commit 45883e0

Browse files
Fix: extra line breaks upon copying code snippets (#9391)
* fix: prioritize copying code block dom node `.textContent` to avoid extra `\n` * fix: make highlited/diff lines background take full width of code blocks * [getsentry/action-github-commit] Auto commit --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent 070b25c commit 45883e0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/components/codeBlock.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function CodeBlock({filename, language, children}: CodeBlockProps) {
2828
return;
2929
}
3030

31-
let code = codeRef.current.innerText;
31+
let code =
32+
codeRef.current.textContent || codeRef.current.innerText.replace(/\n\n/g, '\n');
3233

3334
// don't copy leading prompt for bash
3435
if (language === 'bash' || language === 'shell') {

src/styles/_includes/code-blocks.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@
8181
.code-line {
8282
display: block;
8383
float: left;
84+
// fallback for browsers that don't support calc
85+
// yes it should come before the calc
8486
min-width: 100%;
87+
min-width: calc(100% + 24px);
8588
padding-left: 8px;
8689
margin-left: -12px;
8790
box-sizing: border-box;
@@ -97,8 +100,6 @@
97100
.code-line.diff-inserted,
98101
.code-line.inserted {
99102
background-color: rgba(16, 185, 129, 0.2); /* Set inserted line (+) color */
100-
float: left;
101-
min-width: 100%;
102103
}
103104

104105
.code-line.diff-deleted,

0 commit comments

Comments
 (0)