From 308c663233cafe440f991eff211fb1b5213b219c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 27 Apr 2022 14:45:41 +1000 Subject: [PATCH] Reset filtered decks at import time Before this change, filtered decks exported with scheduling remained filtered on import, and maybe_remove_from_filtered_deck() moved cards into them as their home deck, leading to errors during review. We may still want to provide a way to preserve filtered decks on import, but to do that we'll need to ensure we don't rewrite the home decks of cards, and we'll need to ensure the home decks are included as part of the import (or give an error if they're not). https://github.com/ankitects/anki/pull/1743/files#r839346423 --- rslib/src/import_export/gather.rs | 11 ++++------- rslib/src/import_export/package/apkg/import/decks.rs | 6 ++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rslib/src/import_export/gather.rs b/rslib/src/import_export/gather.rs index 2634751b5..0dc93f9cb 100644 --- a/rslib/src/import_export/gather.rs +++ b/rslib/src/import_export/gather.rs @@ -9,7 +9,7 @@ use std::{ use itertools::Itertools; use crate::{ - decks::{immediate_parent_name, NormalDeck}, + decks::immediate_parent_name, io::filename_is_safe, latex::extract_latex, prelude::*, @@ -89,11 +89,7 @@ impl ExchangeData { if let Ok(normal_mut) = deck.normal_mut() { normal_mut.config_id = 1; } else { - // TODO: scheduling case - deck.kind = DeckKind::Normal(NormalDeck { - config_id: 1, - ..Default::default() - }) + // filtered decks are reset at import time for legacy reasons } } } @@ -102,7 +98,8 @@ impl ExchangeData { let mut position = col.get_next_card_position(); for card in self.cards.iter_mut() { // schedule_as_new() removes cards from filtered decks, but we want to - // leave cards in their current deck, and export filtered as regular decks + // leave cards in their current deck, which gets converted to a regular + // deck on import let deck_id = card.deck_id; if card.schedule_as_new(position, true, true) { position += 1; diff --git a/rslib/src/import_export/package/apkg/import/decks.rs b/rslib/src/import_export/package/apkg/import/decks.rs index 35b035a54..91b157549 100644 --- a/rslib/src/import_export/package/apkg/import/decks.rs +++ b/rslib/src/import_export/package/apkg/import/decks.rs @@ -64,6 +64,12 @@ impl DeckContext<'_> { } } else { self.ensure_valid_first_existing_parent(deck)?; + if deck.is_filtered() { + deck.kind = DeckKind::Normal(NormalDeck { + config_id: 1, + ..Default::default() + }); + } self.add_deck(deck) } }