mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
parent
03c50c8332
commit
b933796a51
1 changed files with 21 additions and 2 deletions
|
@ -497,9 +497,9 @@ fn maybe_set_tags_column(metadata: &mut CsvMetadata, meta_columns: &HashSet<usiz
|
||||||
if metadata.tags_column == 0 {
|
if metadata.tags_column == 0 {
|
||||||
if let Some(CsvNotetype::GlobalNotetype(ref global)) = metadata.notetype {
|
if let Some(CsvNotetype::GlobalNotetype(ref global)) = metadata.notetype {
|
||||||
let max_field = global.field_columns.iter().max().copied().unwrap_or(0);
|
let max_field = global.field_columns.iter().max().copied().unwrap_or(0);
|
||||||
for idx in (max_field + 1) as usize..metadata.column_labels.len() {
|
for idx in (max_field + 1) as usize..=metadata.column_labels.len() {
|
||||||
if !meta_columns.contains(&idx) {
|
if !meta_columns.contains(&idx) {
|
||||||
metadata.tags_column = max_field + 1;
|
metadata.tags_column = idx as u32;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -843,4 +843,23 @@ pub(in crate::import_export) mod test {
|
||||||
);
|
);
|
||||||
assert_eq!(metadata!(col, "\u{feff}tags:foo\n").global_tags, ["foo"]);
|
assert_eq!(metadata!(col, "\u{feff}tags:foo\n").global_tags, ["foo"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_not_set_tags_column_if_all_are_field_columns() {
|
||||||
|
let meta_columns = Default::default();
|
||||||
|
let mut metadata = CsvMetadata::defaults_for_testing();
|
||||||
|
maybe_set_tags_column(&mut metadata, &meta_columns);
|
||||||
|
assert_eq!(metadata.tags_column, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_set_tags_column_to_next_unused_column() {
|
||||||
|
let mut meta_columns = HashSet::default();
|
||||||
|
meta_columns.insert(3);
|
||||||
|
let mut metadata = CsvMetadata::defaults_for_testing();
|
||||||
|
metadata.column_labels.push(String::new());
|
||||||
|
metadata.column_labels.push(String::new());
|
||||||
|
maybe_set_tags_column(&mut metadata, &meta_columns);
|
||||||
|
assert_eq!(metadata.tags_column, 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue