Skip to content

Commit

Permalink
feat(snippets): copy screenshot to clipboard (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Jan 11, 2023
1 parent 891b548 commit f06b084
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/renderer/components/screenshot/TheScreenshot.vue
Expand Up @@ -131,7 +131,8 @@ const props = defineProps<Props>()
const appStore = useAppStore()
const snippetStore = useSnippetStore()
const { escape } = useMagicKeys()
// eslint-disable-next-line camelcase
const { escape, Meta_C, Ctrl_C } = useMagicKeys()
const frameRef = ref<HTMLElement>()
const snippetRef = ref<HTMLElement>()
Expand Down Expand Up @@ -250,6 +251,12 @@ const onSaveScreenshot = async (type: 'png' | 'svg' = 'png') => {
track('snippets/create-screenshot')
}
const copyToClipboard = async () => {
const data = await domToImage.toBlob(snippetRef.value!)
navigator.clipboard.write([new ClipboardItem({ 'image/png': data })])
track('snippets/create-screenshot')
}
watch(
() => appStore.screenshot.darkMode,
v => {
Expand All @@ -269,10 +276,6 @@ watch(
{ deep: true }
)
watch(escape, () => {
snippetStore.isScreenshotPreview = false
})
watch(
() => props.snippet,
v => setValue(v)
Expand All @@ -282,6 +285,21 @@ watch(
v => setLang(v)
)
watch(escape, () => {
snippetStore.isScreenshotPreview = false
})
watch(Meta_C, v => {
if (v) {
copyToClipboard()
}
})
watch(Ctrl_C, v => {
if (v) {
copyToClipboard()
}
})
onMounted(() => {
init()
})
Expand Down

0 comments on commit f06b084

Please sign in to comment.