mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Allow duplicate templates if {{Card}}
is used
This commit is contained in:
parent
c0dd769090
commit
d6e5f3c67c
1 changed files with 18 additions and 14 deletions
|
@ -12,6 +12,7 @@ mod stock;
|
||||||
mod templates;
|
mod templates;
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
||||||
|
use regex::Regex;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
iter::FromIterator,
|
iter::FromIterator,
|
||||||
|
@ -332,21 +333,24 @@ impl Notetype {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_template_fronts_unique(&self) -> Result<()> {
|
fn ensure_template_fronts_unique(&self) -> Result<()> {
|
||||||
let mut map = HashMap::new();
|
lazy_static! {
|
||||||
if let Some((index_1, index_2)) =
|
static ref CARD_TAG: Regex = Regex::new(r"\{\{\s*Card\s*\}\}").unwrap();
|
||||||
self.templates.iter().enumerate().find_map(|(index, card)| {
|
|
||||||
map.insert(&card.config.q_format, index)
|
|
||||||
.map(|old_index| (old_index, index))
|
|
||||||
})
|
|
||||||
{
|
|
||||||
Err(AnkiError::TemplateSaveError(TemplateSaveError {
|
|
||||||
notetype: self.name.clone(),
|
|
||||||
ordinal: index_2,
|
|
||||||
details: TemplateSaveErrorDetails::Duplicate(index_1),
|
|
||||||
}))
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut map = HashMap::new();
|
||||||
|
for (index, card) in self.templates.iter().enumerate() {
|
||||||
|
if let Some(old_index) = map.insert(&card.config.q_format, index) {
|
||||||
|
if !CARD_TAG.is_match(&card.config.q_format) {
|
||||||
|
return Err(AnkiError::TemplateSaveError(TemplateSaveError {
|
||||||
|
notetype: self.name.clone(),
|
||||||
|
ordinal: index,
|
||||||
|
details: TemplateSaveErrorDetails::Duplicate(old_index),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure no templates are None, every front template contains at least one
|
/// Ensure no templates are None, every front template contains at least one
|
||||||
|
|
Loading…
Reference in a new issue