Always generate missing cards when saving card templates
https://forums.ankiweb.net/t/anki-doesnt-generate-cards-after-un-doing-selective-card-generation/20283
This commit is contained in:
parent
2a9a6c5242
commit
5d835ae813
@ -133,18 +133,15 @@ impl Collection {
|
|||||||
previous_template_count: usize,
|
previous_template_count: usize,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let ords: Vec<_> = nt.templates.iter().map(|f| f.ord).collect();
|
let ords: Vec<_> = nt.templates.iter().map(|f| f.ord).collect();
|
||||||
if !ords_changed(&ords, previous_template_count) {
|
|
||||||
// nothing to do
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
self.set_schema_modified()?;
|
|
||||||
let usn = self.usn()?;
|
let usn = self.usn()?;
|
||||||
|
if ords_changed(&ords, previous_template_count) {
|
||||||
|
self.set_schema_modified()?;
|
||||||
let changes = TemplateOrdChanges::new(ords, previous_template_count as u32);
|
let changes = TemplateOrdChanges::new(ords, previous_template_count as u32);
|
||||||
|
|
||||||
// remove any cards where the template was deleted
|
// remove any cards where the template was deleted
|
||||||
if !changes.removed.is_empty() {
|
if !changes.removed.is_empty() {
|
||||||
let ords = SearchBuilder::any(changes.removed.into_iter().map(TemplateKind::Ordinal));
|
let ords =
|
||||||
|
SearchBuilder::any(changes.removed.into_iter().map(TemplateKind::Ordinal));
|
||||||
self.search_cards_into_table(nt.id.and(ords), SortMode::NoOrder)?;
|
self.search_cards_into_table(nt.id.and(ords), SortMode::NoOrder)?;
|
||||||
for card in self.storage.all_searched_cards()? {
|
for card in self.storage.all_searched_cards()? {
|
||||||
self.remove_card_and_add_grave_undoable(card, usn)?;
|
self.remove_card_and_add_grave_undoable(card, usn)?;
|
||||||
@ -154,7 +151,8 @@ impl Collection {
|
|||||||
|
|
||||||
// update ordinals for cards with a repositioned template
|
// update ordinals for cards with a repositioned template
|
||||||
if !changes.moved.is_empty() {
|
if !changes.moved.is_empty() {
|
||||||
let ords = SearchBuilder::any(changes.moved.keys().cloned().map(TemplateKind::Ordinal));
|
let ords =
|
||||||
|
SearchBuilder::any(changes.moved.keys().cloned().map(TemplateKind::Ordinal));
|
||||||
self.search_cards_into_table(nt.id.and(ords), SortMode::NoOrder)?;
|
self.search_cards_into_table(nt.id.and(ords), SortMode::NoOrder)?;
|
||||||
for mut card in self.storage.all_searched_cards()? {
|
for mut card in self.storage.all_searched_cards()? {
|
||||||
let original = card.clone();
|
let original = card.clone();
|
||||||
@ -163,9 +161,10 @@ impl Collection {
|
|||||||
}
|
}
|
||||||
self.storage.clear_searched_cards_table()?;
|
self.storage.clear_searched_cards_table()?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let last_deck = self.get_last_deck_added_to_for_notetype(nt.id);
|
let last_deck = self.get_last_deck_added_to_for_notetype(nt.id);
|
||||||
let ctx = CardGenContext::new(nt, last_deck, self.usn()?);
|
let ctx = CardGenContext::new(nt, last_deck, usn);
|
||||||
self.generate_cards_for_notetype(&ctx)?;
|
self.generate_cards_for_notetype(&ctx)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user