Skip to content

Commit

Permalink
fix: Do not copy deleted lines (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama authored Oct 8, 2023
1 parent db46ec6 commit 4898bfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/healthy-badgers-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/site-kit": patch
---

fix: Do not copy deleted lines
12 changes: 11 additions & 1 deletion packages/site-kit/src/lib/actions/copy-code-descendants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ export const copy_code_descendants = (node) => {
// Exclude the ts-block properties and stuff
if (/ts-block/.test(parent_class)) continue;

const code = block.querySelector('code')?.innerText ?? '';
let code = '';
for (const node of block.querySelector('code')?.childNodes ?? []) {
if (node.nodeType === Node.ELEMENT_NODE) {
if (!(/** @type {HTMLElement} */ (node).classList.contains('deleted'))) {
code += node.textContent;
}
} else {
code += node.textContent;
}
}

if (!code) continue;

// This is to make sure that snippets with title get the button on their heading area
Expand Down

0 comments on commit 4898bfd

Please sign in to comment.