Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix csv columns potentially being numbered wrongly in the header when exporting #3690

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions rslib/src/import_export/text/csv/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,23 @@ impl NoteContext {
}

fn deck_column(&self) -> Option<usize> {
self.with_deck
.then(|| 1 + self.notetype_column().unwrap_or_default())
self.with_deck.then(|| {
1 + self
.notetype_column()
.or_else(|| self.guid_column())
.unwrap_or_default()
})
}

fn tags_column(&self) -> Option<usize> {
self.with_tags
.then(|| 1 + self.deck_column().unwrap_or_default() + self.field_columns)
self.with_tags.then(|| {
1 + self
.deck_column()
.or_else(|| self.notetype_column())
.or_else(|| self.guid_column())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm missing something - why fall back on notetype/guid here when deck_column() does that already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for when the deck column isn't exported, in which case deck_column returns None and tags_column then has to fall back to the next earliest column(s)

Otherwise, the tags column would be 1 + 0 + the number of fields, potentially overlapping with the guid and notetype columns if they exist

This is the same for all the columns, they have to keep falling back to the next earliest non-None column

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 thanks :-)

.unwrap_or_default()
+ self.field_columns
})
}

fn record<'c, 's: 'c, 'n: 'c>(&'s self, note: &'n Note) -> impl Iterator<Item = Cow<'c, [u8]>> {
Expand Down