mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Export getTypedAnswer
This commit is contained in:
parent
af12756980
commit
afa8f8a6f0
2 changed files with 16 additions and 8 deletions
|
@ -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 ""
|
||||
|
|
|
@ -8,13 +8,16 @@ declare const MathJax: any;
|
|||
|
||||
type Callback = () => void | Promise<void>;
|
||||
|
||||
export const ankiPlatform = "desktop";
|
||||
export let typeans: HTMLElement | undefined;
|
||||
let _updatingQueue: Promise<void> = Promise.resolve();
|
||||
|
||||
export const onUpdateHook: Array<Callback> = [];
|
||||
export const onShownHook: Array<Callback> = [];
|
||||
|
||||
export const ankiPlatform = "desktop";
|
||||
let typeans: HTMLInputElement | undefined;
|
||||
|
||||
export function getTypedAnswer(): string | null {
|
||||
return typeans?.value ?? null;
|
||||
}
|
||||
|
||||
function _runHook(arr: Array<Callback>): Promise<void[]> {
|
||||
const promises: (Promise<void> | void)[] = [];
|
||||
|
||||
|
@ -25,6 +28,8 @@ function _runHook(arr: Array<Callback>): Promise<void[]> {
|
|||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
let _updatingQueue: Promise<void> = Promise.resolve();
|
||||
|
||||
function _queueAction(action: Callback): void {
|
||||
_updatingQueue = _updatingQueue.then(action);
|
||||
}
|
||||
|
@ -60,8 +65,11 @@ async function _updateQA(
|
|||
onupdate: Callback,
|
||||
onshown: Callback
|
||||
): Promise<void> {
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue