Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new reviewer): type in the answer (native) #17647

Merged
merged 11 commits into from
Dec 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class PreviewerViewModel(
if (showingAnswer.value) {
typeAnsAnswerFilter(currentCard.await(), text)
} else {
typeAnsQuestionFilter(text)
removeTypeAnswerTags(text)
}

companion object {
Expand All @@ -255,9 +255,9 @@ class PreviewerViewModel(
}
}

/** removes `[[type:]]` blocks in questions */
/** removes `[[type:]]` tags */
@VisibleForTesting
fun typeAnsQuestionFilter(text: String) = typeAnsRe.replace(text, "")
fun removeTypeAnswerTags(text: String) = typeAnsRe.replace(text, "")

/** Adapted from the [desktop code](https://github.com/ankitects/anki/blob/1ff55475b93ac43748d513794bcaabd5d7df6d9d/qt/aqt/reviewer.py#L720) */
suspend fun typeAnsAnswerFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ object LanguageHintService {
Timber.i("Set field locale to %s", selectedLocale)
}

fun getImeHintLocales(field: JSONObject?): LocaleList? {
david-allison marked this conversation as resolved.
Show resolved Hide resolved
if (field == null) return null
return getLanguageHintForField(field)?.let { LocaleList(it) }
}

fun EditText.applyLanguageHint(languageHint: LanguageHint?) {
this.imeHintLocales = if (languageHint != null) LocaleList(languageHint) else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PreviewerViewModelTest {
@Test
fun `type answer fields are removed in questions`() {
assertThat(
PreviewerViewModel.typeAnsQuestionFilter("creu [[type:leu]]"),
PreviewerViewModel.removeTypeAnswerTags("creu [[type:leu]]"),
equalTo("creu "),
)
}
Expand Down