Skip to content

Commit

Permalink
fix: copy no longer working
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Sep 26, 2022
1 parent ec834d0 commit 7899b73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Expand Up @@ -4,7 +4,7 @@ import EmptyPane from '@front/features/layout/EmptyPane.vue'
import RenderCode from './RenderCode.vue'
import { defineComponent, ref, watch, computed } from 'vue'
import { getComponentDisplayName, SharedData } from '@vue-devtools/shared-utils'
import { copyToClipboard, getComponentDisplayName, SharedData } from '@vue-devtools/shared-utils'
import { onKeyDown } from '@front/util/keyboard'
import { useSelectedComponent } from './composable'
Expand Down Expand Up @@ -45,7 +45,7 @@ export default defineComponent({
const showCopiedName = ref(false)
let copiedNameTimeout
function copyName () {
navigator.clipboard.writeText(displayName.value)
copyToClipboard(displayName.value)
showCopiedName.value = true
clearTimeout(copiedNameTimeout)
copiedNameTimeout = setTimeout(() => {
Expand Down
9 changes: 8 additions & 1 deletion packages/shared-utils/src/util.ts
Expand Up @@ -741,7 +741,14 @@ export function copyToClipboard (state) {
text = stringify(state, 'user')
}

navigator.clipboard.writeText(text)
// @TODO navigator.clipboard is buggy in extensions
if (typeof document === 'undefined') return
const dummyTextArea = document.createElement('textarea')
dummyTextArea.textContent = text
document.body.appendChild(dummyTextArea)
dummyTextArea.select()
document.execCommand('copy')
document.body.removeChild(dummyTextArea)
}

export function isEmptyObject (obj) {
Expand Down

0 comments on commit 7899b73

Please sign in to comment.