Skip to content

Commit 282e578

Browse files
authored
Add notification when correctly copying hash commit (#1376)
1 parent c705712 commit 282e578

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
* add `regex-fancy` and `regex-onig` features to allow building Syntect with Onigumara regex engine instead of the default engine based on fancy-regex [[@jirutka](https://github.com/jirutka)]
2828
* add `vendor-openssl` feature to allow building without vendored openssl [[@jirutka](https://github.com/jirutka)]
2929
* allow copying marked commits [[@remique](https://github.com/remique)] ([#1288](https://github.com/extrawurst/gitui/issues/1288))
30+
* Feedback for success/failure of copying hash commit [[@sergioribera]](https://github.com/sergioribera)([#1160](https://github.com/extrawurst/gitui/issues/1160))
3031
* display tags and branches in the log view [[@alexmaco]](https://github.com/alexmaco)([#1371](https://github.com/extrawurst/gitui/pull/1371))
3132
* display current repository path in the top-right corner [[@alexmaco]](https://github.com/alexmaco)([#1387](https://github.com/extrawurst/gitui/pull/1387))
3233

src/components/commitlist.rs

+45-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::{
55
Component, DrawableComponent, EventState, ScrollType,
66
},
77
keys::{key_match, SharedKeyConfig},
8-
strings::{self, symbol},
8+
queue::{InternalEvent, Queue},
9+
strings::{self, copy_fail, copy_success, symbol},
910
ui::style::{SharedTheme, Theme},
1011
ui::{calc_scroll_top, draw_scrollbar},
1112
};
@@ -41,6 +42,7 @@ pub struct CommitList {
4142
current_size: Cell<(u16, u16)>,
4243
scroll_top: Cell<usize>,
4344
theme: SharedTheme,
45+
queue: Queue,
4446
key_config: SharedKeyConfig,
4547
}
4648

@@ -49,6 +51,7 @@ impl CommitList {
4951
pub fn new(
5052
title: &str,
5153
theme: SharedTheme,
54+
queue: Queue,
5255
key_config: SharedKeyConfig,
5356
) -> Self {
5457
Self {
@@ -62,6 +65,7 @@ impl CommitList {
6265
current_size: Cell::new((0, 0)),
6366
scroll_top: Cell::new(0),
6467
theme,
68+
queue,
6569
key_config,
6670
title: title.into(),
6771
}
@@ -178,7 +182,15 @@ impl CommitList {
178182
if let (Some(f), Some(l)) = (first, last) {
179183
let yank =
180184
format!("{}^..{}", f.hash_short, l.hash_short);
181-
crate::clipboard::copy_string(&yank)?;
185+
if let Err(e) = crate::clipboard::copy_string(&yank) {
186+
self.queue.push(InternalEvent::ShowErrorMsg(
187+
copy_fail(&e.to_string()),
188+
));
189+
return Err(e);
190+
}
191+
self.queue.push(InternalEvent::ShowInfoMsg(
192+
copy_success(&yank),
193+
));
182194
};
183195
} else {
184196
let separate = self
@@ -194,7 +206,15 @@ impl CommitList {
194206
})
195207
.join(" ");
196208

197-
crate::clipboard::copy_string(&separate)?;
209+
if let Err(e) = crate::clipboard::copy_string(&separate) {
210+
self.queue.push(InternalEvent::ShowErrorMsg(
211+
copy_fail(&e.to_string()),
212+
));
213+
return Err(e);
214+
}
215+
self.queue.push(InternalEvent::ShowInfoMsg(
216+
copy_success(&separate),
217+
));
198218
}
199219

200220
Ok(())
@@ -207,14 +227,34 @@ impl CommitList {
207227
self.selection
208228
.saturating_sub(self.items.index_offset()),
209229
) {
210-
crate::clipboard::copy_string(&e.hash_short)?;
230+
if let Err(e) =
231+
crate::clipboard::copy_string(&e.hash_short)
232+
{
233+
self.queue.push(InternalEvent::ShowErrorMsg(
234+
copy_fail(&e.to_string()),
235+
));
236+
return Err(e);
237+
}
238+
self.queue.push(InternalEvent::ShowInfoMsg(
239+
copy_success(&e.hash_short),
240+
));
211241
}
212242
}
213243
1 => {
214244
if let Some(e) =
215245
self.items.iter().nth(self.marked_indexes()[0])
216246
{
217-
crate::clipboard::copy_string(&e.hash_short)?;
247+
if let Err(e) =
248+
crate::clipboard::copy_string(&e.hash_short)
249+
{
250+
self.queue.push(InternalEvent::ShowErrorMsg(
251+
copy_fail(&e.to_string()),
252+
));
253+
return Err(e);
254+
}
255+
self.queue.push(InternalEvent::ShowInfoMsg(
256+
copy_success(&e.hash_short),
257+
));
218258
}
219259
}
220260
_ => {}

src/strings.rs

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub static PUSH_TAGS_STATES_DONE: &str = "done";
3030
pub static POPUP_TITLE_SUBMODULES: &str = "Submodules";
3131
pub static POPUP_TITLE_FUZZY_FIND: &str = "Fuzzy Finder";
3232

33+
pub static POPUP_FAIL_COPY: &str = "Failed to copy the Text";
34+
pub static POPUP_SUCCESS_COPY: &str = "Copied Text";
35+
3336
pub mod symbol {
3437
pub const WHITESPACE: &str = "\u{00B7}"; //·
3538
pub const CHECKMARK: &str = "\u{2713}"; //✓
@@ -353,6 +356,14 @@ pub fn rename_branch_popup_msg(
353356
"new branch name".to_string()
354357
}
355358

359+
pub fn copy_success(s: &str) -> String {
360+
format!("{POPUP_SUCCESS_COPY} \"{s}\"")
361+
}
362+
363+
pub fn copy_fail(e: &str) -> String {
364+
format!("{POPUP_FAIL_COPY}: {e}")
365+
}
366+
356367
pub fn ellipsis_trim_start(s: &str, width: usize) -> Cow<str> {
357368
if s.width() <= width {
358369
Cow::Borrowed(s)

src/tabs/revlog.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl Revlog {
6262
list: CommitList::new(
6363
&strings::log_title(&key_config),
6464
theme,
65+
queue.clone(),
6566
key_config.clone(),
6667
),
6768
git_log: AsyncLog::new(

src/tabs/stashlist.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl StashList {
3434
list: CommitList::new(
3535
&strings::stashlist_title(&key_config),
3636
theme,
37+
queue.clone(),
3738
key_config.clone(),
3839
),
3940
queue: queue.clone(),

0 commit comments

Comments
 (0)