mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Apply tag fix from Abdo
https://forums.ankiweb.net/t/drag-and-drop-tag-groups-crashes-anki/35505/3
This commit is contained in:
parent
03778caff9
commit
67acdc3034
1 changed files with 10 additions and 4 deletions
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use unicase::UniCase;
|
||||||
|
|
||||||
use super::join_tags;
|
use super::join_tags;
|
||||||
use super::matcher::TagMatcher;
|
use super::matcher::TagMatcher;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -62,8 +64,12 @@ impl Collection {
|
||||||
// replace tags
|
// replace tags
|
||||||
for mut note in matched_notes {
|
for mut note in matched_notes {
|
||||||
let original = note.clone();
|
let original = note.clone();
|
||||||
note.tags = matcher
|
note.tags = matcher.replace_with_fn(¬e.tags, |cap| {
|
||||||
.replace_with_fn(¬e.tags, |cap| old_to_new_names.get(cap).unwrap().clone());
|
old_to_new_names
|
||||||
|
.get(&UniCase::new(cap.to_string()))
|
||||||
|
.unwrap()
|
||||||
|
.clone()
|
||||||
|
});
|
||||||
note.set_modified(usn);
|
note.set_modified(usn);
|
||||||
self.update_note_tags_undoable(¬e, original)?;
|
self.update_note_tags_undoable(¬e, original)?;
|
||||||
}
|
}
|
||||||
|
@ -80,13 +86,13 @@ impl Collection {
|
||||||
fn old_to_new_names(
|
fn old_to_new_names(
|
||||||
tags_to_reparent: &[String],
|
tags_to_reparent: &[String],
|
||||||
new_parent: Option<String>,
|
new_parent: Option<String>,
|
||||||
) -> HashMap<&str, String> {
|
) -> HashMap<UniCase<String>, String> {
|
||||||
tags_to_reparent
|
tags_to_reparent
|
||||||
.iter()
|
.iter()
|
||||||
// generate resulting names and filter out invalid ones
|
// generate resulting names and filter out invalid ones
|
||||||
.flat_map(|source_tag| {
|
.flat_map(|source_tag| {
|
||||||
reparented_name(source_tag, new_parent.as_deref())
|
reparented_name(source_tag, new_parent.as_deref())
|
||||||
.map(|output_name| (source_tag.as_str(), output_name))
|
.map(|output_name| (UniCase::new(source_tag.to_owned()), output_name))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue