From 1fa99c97e4b555efb24dee27aa2571a88c166ff1 Mon Sep 17 00:00:00 2001 From: RREEMMII <64311122+rreemmii-dev@users.noreply.github.com> Date: Sun, 13 Apr 2025 06:40:35 +0200 Subject: [PATCH] Add a warning when there is a cloze in "back extra" and "text" is empty (#3912) * Add a warning when there is a cloze in "back extra" and "text" is empty Fix #3909 * Disallow non-blank first field card * Fix Rust ninja check --- CONTRIBUTORS | 1 + rslib/src/notes/mod.rs | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 9c6ec7366..4725cc6aa 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -219,6 +219,7 @@ Jakub Fidler Valerie Enfys Julien Chol ikkz +rreemmii-dev ******************** diff --git a/rslib/src/notes/mod.rs b/rslib/src/notes/mod.rs index 851ffaa25..2243a916d 100644 --- a/rslib/src/notes/mod.rs +++ b/rslib/src/notes/mod.rs @@ -594,27 +594,29 @@ impl Collection { /// notetypes, check if there is a cloze in a non-cloze field or if there's /// no cloze at all. For other notetypes, just check if there's a cloze. pub fn note_fields_check(&mut self, note: &Note) -> Result { - Ok(if let Some(text) = note.fields.first() { - let field1 = if self.get_config_bool(BoolKey::NormalizeNoteText) { - normalize_to_nfc(text) - } else { - text.into() - }; - let stripped = strip_html_preserving_media_filenames(&field1); - if stripped.trim().is_empty() { - NoteFieldsState::Empty - } else { - let cloze_state = self.field_cloze_check(note)?; - if cloze_state != NoteFieldsState::Normal { + Ok({ + let cloze_state = self.field_cloze_check(note)?; + if cloze_state == NoteFieldsState::FieldNotCloze { + NoteFieldsState::FieldNotCloze + } else if let Some(text) = note.fields.first() { + let field1 = if self.get_config_bool(BoolKey::NormalizeNoteText) { + normalize_to_nfc(text) + } else { + text.into() + }; + let stripped = strip_html_preserving_media_filenames(&field1); + if stripped.trim().is_empty() { + NoteFieldsState::Empty + } else if cloze_state != NoteFieldsState::Normal { cloze_state } else if self.is_duplicate(&stripped, note)? { NoteFieldsState::Duplicate } else { NoteFieldsState::Normal } + } else { + NoteFieldsState::Empty } - } else { - NoteFieldsState::Empty }) }