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

Copy whole row joined with tabs when cell not selected #97

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ impl App {
.transient_message
.replace(format!("Failed to copy to clipboard: {e}")),
};
} else if let Some((index, row)) = self.rows_view.get_row_value() {
match self.clipboard.as_mut().map(|c| c.set_text(&row)) {
Ok(_) => self
.transient_message
.replace(format!("Copied row {} to clipboard", index)),
Err(e) => self
.transient_message
.replace(format!("Failed to copy to clipboard: {e}")),
Copy link
Owner

Choose a reason for hiding this comment

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

It would be nice if there is a way to reduce the duplication between this if block and the above.

};
}
}
Control::Reset => {
Expand Down
9 changes: 9 additions & 0 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ impl RowsView {
None
}

pub fn get_row_value(&self) -> Option<(usize, String)> {
if let Some(row_index) = self.selection.row.index() {
if let Some(row) = self.rows().get(row_index as usize) {
return Some((row.record_num, row.fields.join("\t")));
}
}
None
}

pub fn num_rows(&self) -> u64 {
self.num_rows
}
Expand Down
Loading