Skip to content

Commit f06b084

Browse files
feat(snippets): copy screenshot to clipboard (#327)
1 parent 891b548 commit f06b084

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/renderer/components/screenshot/TheScreenshot.vue

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ const props = defineProps<Props>()
131131
132132
const appStore = useAppStore()
133133
const snippetStore = useSnippetStore()
134-
const { escape } = useMagicKeys()
134+
// eslint-disable-next-line camelcase
135+
const { escape, Meta_C, Ctrl_C } = useMagicKeys()
135136
136137
const frameRef = ref<HTMLElement>()
137138
const snippetRef = ref<HTMLElement>()
@@ -250,6 +251,12 @@ const onSaveScreenshot = async (type: 'png' | 'svg' = 'png') => {
250251
track('snippets/create-screenshot')
251252
}
252253
254+
const copyToClipboard = async () => {
255+
const data = await domToImage.toBlob(snippetRef.value!)
256+
navigator.clipboard.write([new ClipboardItem({ 'image/png': data })])
257+
track('snippets/create-screenshot')
258+
}
259+
253260
watch(
254261
() => appStore.screenshot.darkMode,
255262
v => {
@@ -269,10 +276,6 @@ watch(
269276
{ deep: true }
270277
)
271278
272-
watch(escape, () => {
273-
snippetStore.isScreenshotPreview = false
274-
})
275-
276279
watch(
277280
() => props.snippet,
278281
v => setValue(v)
@@ -282,6 +285,21 @@ watch(
282285
v => setLang(v)
283286
)
284287
288+
watch(escape, () => {
289+
snippetStore.isScreenshotPreview = false
290+
})
291+
292+
watch(Meta_C, v => {
293+
if (v) {
294+
copyToClipboard()
295+
}
296+
})
297+
watch(Ctrl_C, v => {
298+
if (v) {
299+
copyToClipboard()
300+
}
301+
})
302+
285303
onMounted(() => {
286304
init()
287305
})

0 commit comments

Comments
 (0)