diff --git a/rslib/src/import_export/text/csv/metadata.rs b/rslib/src/import_export/text/csv/metadata.rs index dfa1cff32..0ed6e1b32 100644 --- a/rslib/src/import_export/text/csv/metadata.rs +++ b/rslib/src/import_export/text/csv/metadata.rs @@ -57,6 +57,7 @@ impl Collection { maybe_set_fallback_columns(&mut metadata)?; self.maybe_set_fallback_notetype(&mut metadata, notetype_id)?; self.maybe_init_notetype_map(&mut metadata)?; + maybe_set_tags_column(&mut metadata); self.maybe_set_fallback_deck(&mut metadata)?; Ok(metadata) @@ -377,6 +378,17 @@ fn maybe_set_fallback_delimiter( Ok(()) } +fn maybe_set_tags_column(metadata: &mut CsvMetadata) { + if metadata.tags_column == 0 { + if let Some(CsvNotetype::GlobalNotetype(ref global)) = metadata.notetype { + let max_field = global.field_columns.iter().max().copied().unwrap_or(0); + if max_field < metadata.column_labels.len() as u32 { + metadata.tags_column = max_field + 1; + } + } + } +} + fn delimiter_from_value(value: &str) -> Option { let normed = value.to_ascii_lowercase(); for delimiter in Delimiter::iter() { diff --git a/ts/import-csv/ImportCsvPage.svelte b/ts/import-csv/ImportCsvPage.svelte index 17a95ef53..bc3bada7e 100644 --- a/ts/import-csv/ImportCsvPage.svelte +++ b/ts/import-csv/ImportCsvPage.svelte @@ -56,7 +56,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html preview[0].vals, notetypeColumn, deckColumn, - tagsColumn, guidColumn, ); $: getCsvMetadata(path, delimiter, undefined, isHtml).then((meta) => { @@ -68,6 +67,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html lastDelimeter = delimiter; getCsvMetadata(path, delimiter, globalNotetype?.id).then((meta) => { globalNotetype = meta.globalNotetype ?? null; + tagsColumn = meta.tagsColumn; }); } diff --git a/ts/import-csv/lib.ts b/ts/import-csv/lib.ts index 5f8a2f78b..e2b1a223e 100644 --- a/ts/import-csv/lib.ts +++ b/ts/import-csv/lib.ts @@ -21,7 +21,6 @@ export function getColumnOptions( firstRow: string[], notetypeColumn: number | null, deckColumn: number | null, - tagsColumn: number, guidColumn: number, ): ColumnOption[] { return [{ label: tr.changeNotetypeNothing(), value: 0, disabled: false }].concat( @@ -33,8 +32,6 @@ export function getColumnOptions( return columnOption(tr.decksDeck(), true, index); } else if (index === guidColumn) { return columnOption("GUID", true, index); - } else if (index === tagsColumn) { - return columnOption(tr.editingTags(), false, index); } else if (label === "") { return columnOption(firstRow[index - 1], false, index, true); } else {