Skip to content

Commit

Permalink
fix: twoslash clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Jan 15, 2024
1 parent 91c778c commit 738864d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-days-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vocs": patch
---

Fixed Twoslash leaking into clipboard.
13 changes: 6 additions & 7 deletions src/app/hooks/useCopyCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ export function useCopyCode() {
function copy() {
setCopied(true)

const lines = ref.current?.querySelectorAll('[data-line]:not(.diff.remove)')

let text = ''
for (const line of lines ?? []) text += `${line.textContent || ''}\n`
text = text.slice(0, -1)

navigator.clipboard.writeText(text)
const node = ref.current?.cloneNode(true) as HTMLPreElement
const nodesToRemove = node?.querySelectorAll(
'button,[data-line].diff.remove,.twoslash-popup-info-hover,.twoslash-popup-info,.twoslash-meta-line,.twoslash-tag-line',
)
for (const node of nodesToRemove ?? []) node.remove()
navigator.clipboard.writeText(node?.textContent as string)
}

return {
Expand Down

0 comments on commit 738864d

Please sign in to comment.