refs #4239 Add shortcut key for post

This commit is contained in:
AkiraFukushima 2023-04-09 00:48:36 +09:00
parent 4a2809c519
commit 3ddba767de
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
1 changed files with 9 additions and 2 deletions

View File

@ -146,7 +146,8 @@ import { MUTATION_TYPES } from '@/store/TimelineSpace/Compose'
import ReceiveDrop from './ReceiveDrop.vue' import ReceiveDrop from './ReceiveDrop.vue'
import Quote from './Compose/Quote.vue' import Quote from './Compose/Quote.vue'
import suggestText from '@/utils/suggestText' 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 = { type Expire = {
label: string label: string
@ -166,7 +167,7 @@ export default defineComponent({
const route = useRoute() const route = useRoute()
const store = useStore() const store = useStore()
const i18n = useI18next() const i18n = useI18next()
const { up, down, enter, escape } = useMagicKeys({ const { up, down, enter, Ctrl_Enter, escape } = useMagicKeys({
passive: false, passive: false,
onEventFired(e) { onEventFired(e) {
if (e.key === 'Enter' && suggestOpened.value) e.preventDefault() if (e.key === 'Enter' && suggestOpened.value) e.preventDefault()
@ -174,6 +175,7 @@ export default defineComponent({
if (e.key === 'ArrowDown' && suggestOpened.value) e.preventDefault() if (e.key === 'ArrowDown' && suggestOpened.value) e.preventDefault()
} }
}) })
const activeElement = useActiveElement()
const space = 'TimelineSpace/Compose' const space = 'TimelineSpace/Compose'
const win = (window as any) as MyWindow const win = (window as any) as MyWindow
@ -258,6 +260,8 @@ export default defineComponent({
const startIndex = ref(0) const startIndex = ref(0)
const matchWord = ref('') const matchWord = ref('')
const shortcutEnabled = computed(() => activeElement.value?.tagName === 'TEXTAREA')
onMounted(async () => { onMounted(async () => {
const [a, s]: [LocalAccount, LocalServer] = await win.ipcRenderer.invoke('get-local-account', id.value) 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) const c = generator(s.sns, s.baseURL, a.accessToken, userAgent.value)
@ -326,6 +330,9 @@ export default defineComponent({
whenever(enter, () => { whenever(enter, () => {
if (suggestOpened.value) selectCurrentItem() if (suggestOpened.value) selectCurrentItem()
}) })
whenever(logicAnd(Ctrl_Enter, shortcutEnabled), async () => {
await post()
})
whenever(escape, () => { whenever(escape, () => {
closeSuggest() closeSuggest()
}) })