We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4246fce commit aaae763Copy full SHA for aaae763
src/utils/copy.ts
@@ -1,18 +1,11 @@
1
+document.addEventListener('copy', (e) => {
2
+ const selectedText = window.getSelection()?.toString() ?? ''
3
+ const cleanedText = selectedText?.replace(/\n+$/, '\n')
4
+ e.clipboardData?.setData('text/plain', cleanedText)
5
+
6
+ e.preventDefault()
7
+})
8
9
export function copyToClip(text: string) {
- return new Promise((resolve, reject) => {
- try {
- const input: HTMLTextAreaElement = document.createElement('textarea')
- input.setAttribute('readonly', 'readonly')
- input.value = text
- document.body.appendChild(input)
- input.select()
- if (document.execCommand('copy'))
10
- document.execCommand('copy')
11
- document.body.removeChild(input)
12
- resolve(text)
13
- }
14
- catch (error) {
15
- reject(error)
16
17
- })
+ return navigator.clipboard.writeText(text)
18
}
0 commit comments