Skip to content

Commit 3101f7b

Browse files
yangantoStephan Dilly
authored andcommitted
copy commit hash
1 parent 587acf2 commit 3101f7b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/components/commitlist.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ impl CommitList {
121121
)
122122
}
123123

124+
pub fn copy_entry_hash(&self) -> Result<()> {
125+
if let Some(e) = self.items.iter().nth(
126+
self.selection.saturating_sub(self.items.index_offset()),
127+
) {
128+
crate::clipboard::copy_string(&e.hash_short)?;
129+
}
130+
Ok(())
131+
}
132+
124133
fn move_selection(&mut self, scroll: ScrollType) -> Result<bool> {
125134
self.update_scroll_speed();
126135

src/tabs/revlog.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ impl Revlog {
151151
self.list.selected_entry().map(|e| e.id)
152152
}
153153

154+
fn copy_commit_hash(&self) -> Result<()> {
155+
self.list.copy_entry_hash()?;
156+
Ok(())
157+
}
158+
154159
fn selected_commit_tags(
155160
&self,
156161
commit: &Option<CommitId>,
@@ -204,6 +209,9 @@ impl Component for Revlog {
204209
self.commit_details.toggle_visible()?;
205210
self.update()?;
206211
return Ok(true);
212+
} else if k == self.key_config.copy {
213+
self.copy_commit_hash()?;
214+
return Ok(true);
207215
} else if k == self.key_config.log_tag_commit {
208216
return self.selected_commit().map_or(
209217
Ok(false),

0 commit comments

Comments
 (0)