Skip to content

Commit

Permalink
fix: remove additional new line insert when copying from code-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Sep 21, 2024
1 parent fa4da3d commit 6409911
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,16 @@ function CodeBlock(props: React.HTMLProps<HTMLPreElement>) {
<button
className="px-2 flex items-center text-gray-500 hover:bg-gray-500 hover:text-gray-100 dark:hover:text-gray-200 transition duration-200"
onClick={() => {
navigator.clipboard.writeText(ref.current?.innerText || '')
let copyContent =
typeof ref.current?.innerText === 'string'
? ref.current.innerText
: ''

if (copyContent.endsWith('\n')) {
copyContent = copyContent.slice(0, -1)
}

navigator.clipboard.writeText(copyContent)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
}}
Expand Down

0 comments on commit 6409911

Please sign in to comment.