mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
remove :{} and leading/trailing whitespace from field names on save
This commit is contained in:
parent
6e8860cafa
commit
8bde0d4ac1
2 changed files with 18 additions and 0 deletions
|
@ -34,4 +34,17 @@ impl NoteField {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn fix_name(&mut self) {
|
||||||
|
// remove special characters
|
||||||
|
let bad_chars = |c| c == ':' || c == '{' || c == '}';
|
||||||
|
if self.name.contains(bad_chars) {
|
||||||
|
self.name = self.name.replace(bad_chars, "");
|
||||||
|
}
|
||||||
|
// and leading/trailing whitespace
|
||||||
|
let trimmed = self.name.trim();
|
||||||
|
if trimmed.len() != self.name.len() {
|
||||||
|
self.name = trimmed.into();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,6 +194,7 @@ impl NoteType {
|
||||||
return Err(AnkiError::invalid_input("1 template required"));
|
return Err(AnkiError::invalid_input("1 template required"));
|
||||||
}
|
}
|
||||||
self.normalize_names();
|
self.normalize_names();
|
||||||
|
self.fix_field_names();
|
||||||
self.ensure_names_unique();
|
self.ensure_names_unique();
|
||||||
self.reposition_sort_idx();
|
self.reposition_sort_idx();
|
||||||
|
|
||||||
|
@ -289,6 +290,10 @@ impl NoteType {
|
||||||
pub fn target_deck_id(&self) -> DeckID {
|
pub fn target_deck_id(&self) -> DeckID {
|
||||||
DeckID(self.config.target_deck_id)
|
DeckID(self.config.target_deck_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fix_field_names(&mut self) {
|
||||||
|
self.fields.iter_mut().for_each(NoteField::fix_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<NoteType> for NoteTypeProto {
|
impl From<NoteType> for NoteTypeProto {
|
||||||
|
|
Loading…
Reference in a new issue