Skip to content

Commit

Permalink
feat(snippets): add copy to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Apr 4, 2022
1 parent 8a66475 commit 1699335
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/renderer/components/snippets/SnippetHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<div class="action">
<AppActionButton>
<UniconsArrow />
<UniconsArrow @click="onCopySnippet" />
</AppActionButton>
<AppActionButton>
<UniconsPlus @click="onAddNewFragment" />
Expand All @@ -26,9 +26,11 @@

<script setup lang="ts">
import { emitter } from '@/composable'
import { ipc } from '@/electron'
import { useSnippetStore } from '@/store/snippets'
import { useDebounceFn } from '@vueuse/core'
import { useClipboard, useDebounceFn } from '@vueuse/core'
import { computed, ref } from 'vue'
import type { NotificationPayload } from '@@/types'
const snippetStore = useSnippetStore()
const inputRef = ref<HTMLInputElement>()
Expand All @@ -47,6 +49,14 @@ const onAddNewFragment = () => {
snippetStore.fragment = snippetStore.fragmentCount!
}
const onCopySnippet = () => {
const { copy } = useClipboard({ source: snippetStore.currentContent })
copy()
ipc.invoke<any, NotificationPayload>('notification', {
body: 'Snippet copied'
})
}
emitter.on('focus:snippet-name', () => {
inputRef.value?.select()
})
Expand Down

0 comments on commit 1699335

Please sign in to comment.