From 3ddba767de387f915ef42cb2ff0c8df75155154d Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Sun, 9 Apr 2023 00:48:36 +0900 Subject: [PATCH] refs #4239 Add shortcut key for post --- src/renderer/components/TimelineSpace/Compose.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/TimelineSpace/Compose.vue b/src/renderer/components/TimelineSpace/Compose.vue index 5c73e6d4..f4319be6 100644 --- a/src/renderer/components/TimelineSpace/Compose.vue +++ b/src/renderer/components/TimelineSpace/Compose.vue @@ -146,7 +146,8 @@ import { MUTATION_TYPES } from '@/store/TimelineSpace/Compose' import ReceiveDrop from './ReceiveDrop.vue' import Quote from './Compose/Quote.vue' import suggestText from '@/utils/suggestText' -import { useMagicKeys, whenever } from '@vueuse/core' +import { useActiveElement, useMagicKeys, whenever } from '@vueuse/core' +import { logicAnd } from '@vueuse/math' type Expire = { label: string @@ -166,7 +167,7 @@ export default defineComponent({ const route = useRoute() const store = useStore() const i18n = useI18next() - const { up, down, enter, escape } = useMagicKeys({ + const { up, down, enter, Ctrl_Enter, escape } = useMagicKeys({ passive: false, onEventFired(e) { if (e.key === 'Enter' && suggestOpened.value) e.preventDefault() @@ -174,6 +175,7 @@ export default defineComponent({ if (e.key === 'ArrowDown' && suggestOpened.value) e.preventDefault() } }) + const activeElement = useActiveElement() const space = 'TimelineSpace/Compose' const win = (window as any) as MyWindow @@ -258,6 +260,8 @@ export default defineComponent({ const startIndex = ref(0) const matchWord = ref('') + const shortcutEnabled = computed(() => activeElement.value?.tagName === 'TEXTAREA') + onMounted(async () => { const [a, s]: [LocalAccount, LocalServer] = await win.ipcRenderer.invoke('get-local-account', id.value) const c = generator(s.sns, s.baseURL, a.accessToken, userAgent.value) @@ -326,6 +330,9 @@ export default defineComponent({ whenever(enter, () => { if (suggestOpened.value) selectCurrentItem() }) + whenever(logicAnd(Ctrl_Enter, shortcutEnabled), async () => { + await post() + }) whenever(escape, () => { closeSuggest() })