Skip to content

Commit

Permalink
Copy whole row joined with tabs when cell not selected (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
mendelmaleh committed Sep 27, 2024
1 parent 1c1a4c5 commit dbbeebb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,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}")),
};
}
}
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

0 comments on commit dbbeebb

Please sign in to comment.