mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Fix deck names differing in case being duplicated in CSV import (#3008)
This commit is contained in:
parent
23291e7172
commit
2b4cb2992b
1 changed files with 7 additions and 5 deletions
|
@ -6,6 +6,8 @@ use std::collections::HashMap;
|
|||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use unicase::UniCase;
|
||||
|
||||
use super::NameOrId;
|
||||
use crate::card::CardQueue;
|
||||
use crate::card::CardType;
|
||||
|
@ -83,7 +85,7 @@ struct Context<'a> {
|
|||
|
||||
struct DeckIdsByNameOrId {
|
||||
ids: HashSet<DeckId>,
|
||||
names: HashMap<String, DeckId>,
|
||||
names: HashMap<UniCase<String>, DeckId>,
|
||||
default: Option<DeckId>,
|
||||
}
|
||||
|
||||
|
@ -146,10 +148,10 @@ impl Duplicate {
|
|||
|
||||
impl DeckIdsByNameOrId {
|
||||
fn new(col: &mut Collection, default: &NameOrId) -> Result<Self> {
|
||||
let names: HashMap<String, DeckId> = col
|
||||
let names: HashMap<UniCase<String>, DeckId> = col
|
||||
.get_all_normal_deck_names(false)?
|
||||
.into_iter()
|
||||
.map(|(id, name)| (name, id))
|
||||
.map(|(id, name)| (UniCase::new(name), id))
|
||||
.collect();
|
||||
let ids = names.values().copied().collect();
|
||||
let mut new = Self {
|
||||
|
@ -166,13 +168,13 @@ impl DeckIdsByNameOrId {
|
|||
match name_or_id {
|
||||
_ if *name_or_id == NameOrId::default() => self.default,
|
||||
NameOrId::Id(id) => self.ids.get(&DeckId(*id)).copied(),
|
||||
NameOrId::Name(name) => self.names.get(name).copied(),
|
||||
NameOrId::Name(name) => self.names.get(&UniCase::new(name.to_string())).copied(),
|
||||
}
|
||||
}
|
||||
|
||||
fn insert(&mut self, deck_id: DeckId, name: String) {
|
||||
self.ids.insert(deck_id);
|
||||
self.names.insert(name, deck_id);
|
||||
self.names.insert(UniCase::new(name), deck_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue