diff --git a/src/index.ts b/src/index.ts index 548d5f8..9e799c7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,13 @@ import { setConfig, validateApiKey, } from "./config.js"; -import { type InsertTarget, insertText, isOpencodePage, submitPrompt } from "./insert.js"; +import { + type InsertTarget, + insertText, + isOpencodePage, + isQuestionPromptOpen, + submitPrompt, +} from "./insert.js"; import { setupKeyboardShortcut } from "./keyboard.js"; import { transcribe } from "./transcribe.js"; import type { DictationState } from "./types.js"; @@ -35,8 +41,8 @@ function stopTimer(): void { } async function toggleDictation(target: InsertTarget): Promise { - currentTarget = target; if (currentState === "idle") { + currentTarget = target; await startRecording(); } else if (currentState === "recording") { await stopAndTranscribe(); @@ -182,7 +188,7 @@ function init(): void { }); setupKeyboardShortcut(() => { - void toggleDictation("composer"); + void toggleDictation(isQuestionPromptOpen() ? "question" : "composer"); }); registerMenuCommands({ diff --git a/src/insert.ts b/src/insert.ts index e96bb29..03b9b6a 100644 --- a/src/insert.ts +++ b/src/insert.ts @@ -8,6 +8,10 @@ export function isOpencodePage(): boolean { return document.querySelector(PROMPT_INPUT_SELECTOR) !== null; } +export function isQuestionPromptOpen(): boolean { + return document.querySelector(QUESTION_INPUT_SELECTOR) !== null; +} + export function insertText(text: string, target: InsertTarget = "composer"): boolean { if (target === "question") { return insertIntoTextarea(text); diff --git a/src/ui.ts b/src/ui.ts index 39c4b4f..2652c73 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -14,7 +14,7 @@ const QUESTION_INPUT_SELECTOR = '[data-slot="question-custom-input"]'; const ICON_MIC = ``; const ICON_STOP = ``; const ICON_CANCEL = ``; -const ICON_SPINNER = ``; +const ICON_SPINNER = ``; function createButtonStyle(): string { return ` @@ -119,7 +119,7 @@ function createButtonStyle(): string { } @keyframes ocvd-spin { from { transform: rotate(0deg); } - to { transform: rotate(-360deg); } + to { transform: rotate(360deg); } } .ocvd-spin { animation: ocvd-spin 0.8s linear infinite;