Skip to content

Commit 396e8ad

Browse files
committed
feat(menu): add copy snippet action to editor menu
1 parent 469e715 commit 396e8ad

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/main/menu/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ const editMenuItems: MenuConfig[] = [
158158
]
159159

160160
const editorMenuItems: MenuConfig[] = [
161+
{
162+
label: i18n.t('menu:editor.copy'),
163+
click: () => send('main-menu:copy-snippet'),
164+
accelerator: 'CommandOrControl+Shift+C',
165+
},
161166
{
162167
label: i18n.t('menu:editor.format'),
163168
accelerator: 'Shift+CommandOrControl+F',

src/main/types/ipc.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ export type CombineWith<T extends string, U extends string> = `${U}:${T}`
44

55
type MainMenuAction =
66
| 'add-description'
7+
| 'copy-snippet'
78
| 'find'
9+
| 'font-size-decrease'
10+
| 'font-size-increase'
11+
| 'font-size-reset'
812
| 'format'
913
| 'goto-preferences'
1014
| 'new-folder'
1115
| 'new-fragment'
1216
| 'new-snippet'
1317
| 'open-dialog'
14-
| 'font-size-increase'
15-
| 'font-size-decrease'
16-
| 'font-size-reset'
1718

1819
type DBAction = 'relaod' | 'move' | 'migrate' | 'clear'
1920
type SystemAction = 'reload'

src/renderer/components/editor/Editor.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { Language } from '@/components/editor/types'
33
import { useEditor, useSnippets, useSnippetUpdate } from '@/composables'
44
import { i18n, ipc } from '@/electron'
5-
import { useDark, useDebounceFn } from '@vueuse/core'
5+
import { useClipboard, useDark, useDebounceFn } from '@vueuse/core'
66
import CodeMirror from 'codemirror'
77
import { EDITOR_DEFAULTS } from '~/main/store/constants'
88
import 'codemirror/addon/edit/closebrackets'
@@ -99,6 +99,11 @@ async function init() {
9999
settings.fontSize = EDITOR_DEFAULTS.fontSize
100100
})
101101
102+
ipc.on('main-menu:copy-snippet', () => {
103+
const { copy } = useClipboard({ source: editor?.getValue() || '' })
104+
copy()
105+
})
106+
102107
watch(selectedSnippetContent, (v) => {
103108
nextTick(() => {
104109
setValue(v?.value || '')

0 commit comments

Comments
 (0)