Fix: Typed answers with no arguments dont work

This commit is contained in:
Luc Mcgrady 2025-11-07 17:08:09 +00:00
parent c843ef135b
commit 7faa2a26e1
No known key found for this signature in database
GPG key ID: 4F3D7A0B17CC3D9C
3 changed files with 23 additions and 10 deletions

View file

@ -297,6 +297,11 @@ message NextCardDataResponse {
string due = 2;
}
message TypedAnswer {
string text = 1;
string args = 2;
}
message NextCardData {
QueuedCards queue = 1;
repeated AnswerButton answer_buttons = 2;
@ -306,8 +311,7 @@ message NextCardDataResponse {
string css = 5;
string body_class = 6;
bool autoplay = 7;
optional string typed_answer = 12;
optional string typed_answer_args = 13;
optional TypedAnswer typed_answer = 12;
repeated card_rendering.AVTag question_av_tags = 8;
repeated card_rendering.AVTag answer_av_tags = 9;

View file

@ -11,6 +11,7 @@ use anki_proto::generic;
use anki_proto::scheduler;
use anki_proto::scheduler::next_card_data_response::AnswerButton;
use anki_proto::scheduler::next_card_data_response::NextCardData;
use anki_proto::scheduler::next_card_data_response::TypedAnswer;
use anki_proto::scheduler::ComputeFsrsParamsResponse;
use anki_proto::scheduler::ComputeMemoryStateResponse;
use anki_proto::scheduler::ComputeOptimalRetentionResponse;
@ -432,7 +433,9 @@ impl crate::services::SchedulerService for Collection {
*text = ANSWER_REGEX
.replace(text, |cap: &regex::Captures<'_>| {
out = Some((
cap.get(1).map(|g| g.as_str().to_string()),
cap.get(1)
.map(|g| g.as_str().to_string())
.unwrap_or("".to_string()),
cap[2].to_string(),
));
ANSWER_HTML
@ -444,10 +447,13 @@ impl crate::services::SchedulerService for Collection {
}
});
let typed_answer = typed_answer_parent_node.as_ref().map(|field| {
let typed_answer = typed_answer_parent_node.map(|field| {
let note = self.get_note(next_card.card.note_id.into()).unwrap();
let notetype = self.get_notetype(note.notetype_id.into()).unwrap().unwrap();
note.fields[notetype.get_field_ord(&field.1).unwrap()].clone()
(
field.0,
note.fields[notetype.get_field_ord(&field.1).unwrap()].clone(),
)
});
Ok(NextCardDataResponse {
@ -460,8 +466,10 @@ impl crate::services::SchedulerService for Collection {
answer_buttons,
autoplay: !config.inner.disable_autoplay,
typed_answer,
typed_answer_args: typed_answer_parent_node.and_then(|v| v.0),
typed_answer: typed_answer.map(|answer| TypedAnswer {
text: answer.1,
args: answer.0,
}),
// Filled by python
front: "".to_string(),

View file

@ -146,13 +146,14 @@ export class ReviewerState {
}
async showTypedAnswer(html: string) {
if (!this._cardData?.typedAnswer || !this._cardData.typedAnswerArgs) {
console.log({ data: this._cardData });
if (this._cardData?.typedAnswer === undefined) {
return html;
}
const compareAnswerResp = await compareAnswer({
expected: this._cardData?.typedAnswer,
expected: this._cardData.typedAnswer.text,
provided: this.currentTypedAnswer,
combining: !this._cardData.typedAnswerArgs.includes("nc"),
combining: !this._cardData.typedAnswer.args.includes("nc"),
});
const display = compareAnswerResp.val;