diff --git a/qt/aqt/reviewer.py b/qt/aqt/reviewer.py index f598740db..a670495ad 100644 --- a/qt/aqt/reviewer.py +++ b/qt/aqt/reviewer.py @@ -694,7 +694,7 @@ class Reviewer: return s def _getTypedAnswer(self) -> None: - self.web.evalWithCallback("typeans ? typeans.value : null", self._onTypedAnswer) + self.web.evalWithCallback("getTypedAnswer();", self._onTypedAnswer) def _onTypedAnswer(self, val: None) -> None: self.typedAnswer = val or "" diff --git a/ts/reviewer/index.ts b/ts/reviewer/index.ts index aa060a7d4..45159af4d 100644 --- a/ts/reviewer/index.ts +++ b/ts/reviewer/index.ts @@ -8,13 +8,16 @@ declare const MathJax: any; type Callback = () => void | Promise; -export const ankiPlatform = "desktop"; -export let typeans: HTMLElement | undefined; -let _updatingQueue: Promise = Promise.resolve(); - export const onUpdateHook: Array = []; export const onShownHook: Array = []; +export const ankiPlatform = "desktop"; +let typeans: HTMLInputElement | undefined; + +export function getTypedAnswer(): string | null { + return typeans?.value ?? null; +} + function _runHook(arr: Array): Promise { const promises: (Promise | void)[] = []; @@ -25,6 +28,8 @@ function _runHook(arr: Array): Promise { return Promise.all(promises); } +let _updatingQueue: Promise = Promise.resolve(); + function _queueAction(action: Callback): void { _updatingQueue = _updatingQueue.then(action); } @@ -60,8 +65,11 @@ async function _updateQA( onupdate: Callback, onshown: Callback ): Promise { - onUpdateHook.splice(0, Infinity, onupdate); - onShownHook.splice(0, Infinity, onshown); + onUpdateHook.length = 0; + onUpdateHook.push(onupdate); + + onShownHook.length = 0; + onShownHook.push(onshown); const qa = document.getElementById("qa")!; const renderError = @@ -116,7 +124,7 @@ export function _showQuestion(q: string, a: string, bodyclass: string): void { }, function () { // focus typing area if visible - typeans = document.getElementById("typeans") as HTMLElement; + typeans = document.getElementById("typeans") as HTMLInputElement; if (typeans) { typeans.focus(); }