diff --git a/src/components/Talk/TalkEditor.vue b/src/components/Talk/TalkEditor.vue index f4399d022e..29942c09de 100644 --- a/src/components/Talk/TalkEditor.vue +++ b/src/components/Talk/TalkEditor.vue @@ -143,7 +143,7 @@ import { SplitterPositionType, Voice, } from "@/type/preload"; -import { parseUnshiftedDigit, useHotkeyManager } from "@/plugins/hotkeyPlugin"; +import { useHotkeyManager } from "@/plugins/hotkeyPlugin"; import onetimeWatch from "@/helpers/onetimeWatch"; const props = defineProps<{ @@ -246,34 +246,26 @@ registerHotkeyWithCleanup({ } }, }); -registerHotkeyWithCleanup({ - editor: "talk", - enableInTextbox: true, - name: "N番目のキャラクターを選択", - callback: (e) => { - if (!uiLocked.value) { - onCharacterSelectHotkey(e); - } - }, -}); +for (let i = 0; i < 10; i++) { + registerHotkeyWithCleanup({ + editor: "talk", + enableInTextbox: true, + name: `${i + 1}番目のキャラクターを選択`, + callback: () => { + if (!uiLocked.value) { + onCharacterSelectHotkey(i); + } + }, + }); +} const removeAudioItem = async () => { if (activeAudioKey.value == undefined) throw new Error(); audioCellRefs[activeAudioKey.value].removeCell(); }; -const onCharacterSelectHotkey = async (e: KeyboardEvent) => { +const onCharacterSelectHotkey = async (selectedCharacterIndex: number) => { if (activeAudioKey.value == undefined) throw new Error(); - const convertToNumber = (str: string) => { - str = parseUnshiftedDigit(str); - if (/^[0-9]$/.test(str)) { - return parseInt(str, 10); - } else { - throw new Error(`onCharacterSelectHotkey Invalid key: ${str}`); - } - }; - const convertedKey = convertToNumber(e.key); - const selectedCharacterIndex = convertedKey != 0 ? convertedKey - 1 : 9; audioCellRefs[activeAudioKey.value].selectCharacterAt(selectedCharacterIndex); }; diff --git a/src/type/preload.ts b/src/type/preload.ts index 21c92b6d72..7f76020d3e 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -172,6 +172,15 @@ export const defaultHotkeySettings: HotkeySettingType[] = [ action: "選択解除", combination: HotkeyCombination("Escape"), }, + ...Array.from({ length: 10 }, (_, index) => { + const roleKey = index == 9 ? 0 : index + 1; + return { + action: `${index + 1}番目のキャラクターを選択`, + combination: HotkeyCombination( + !isMac ? "Ctrl " + roleKey : "Meta " + roleKey, + ), + }; + }), ]; export const defaultToolbarButtonSetting: ToolbarSettingType = [ @@ -458,6 +467,10 @@ export const hotkeyActionNameSchema = z.enum([ "貼り付け", "すべて選択", "選択解除", + ...Array.from( + { length: 10 }, + (_, index) => `${index + 1}番目のキャラクターを選択`, + ), ]); export type HotkeyActionNameType = z.infer;