diff options
author | qkzk <qu3nt1n@gmail.com> | 2024-01-06 23:31:46 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2024-01-06 23:31:46 +0100 |
commit | df76e74ce36d7b92a9c471f60ae85df7675396b7 (patch) | |
tree | bf4da1a1237cac833e21d0022ded6b738c6cbb4e /src/event/event_exec.rs | |
parent | 4c0ef7e24e3e493c4ea9001c490b56d8a11d3e3a (diff) |
flagged: copy filename & filepath
Diffstat (limited to 'src/event/event_exec.rs')
-rw-r--r-- | src/event/event_exec.rs | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/event/event_exec.rs b/src/event/event_exec.rs index c8974ac..36d901b 100644 --- a/src/event/event_exec.rs +++ b/src/event/event_exec.rs @@ -5,6 +5,8 @@ use anyhow::{Context, Result}; use crate::app::Status; use crate::app::Tab; +use crate::common::filename_to_clipboard; +use crate::common::filepath_to_clipboard; use crate::common::LAZYGIT; use crate::common::NCDU; use crate::common::{is_program_in_path, open_in_current_neovim}; @@ -975,17 +977,41 @@ impl EventAction { } /// Copy the filename of the selected file in normal mode. - pub fn copy_filename(tab: &mut Tab) -> Result<()> { - if let Display::Directory | Display::Tree = tab.display_mode { - tab.filename_to_clipboard(); + pub fn copy_filename(status: &Status) -> Result<()> { + match status.current_tab().display_mode { + Display::Tree | Display::Directory => { + let Ok(file_info) = status.current_tab().current_file() else { + return Ok(()); + }; + filename_to_clipboard(&file_info.path); + } + Display::Flagged => { + let Some(path) = status.menu.flagged.selected() else { + return Ok(()); + }; + filename_to_clipboard(&path); + } + _ => return Ok(()), } Ok(()) } /// Copy the filepath of the selected file in normal mode. - pub fn copy_filepath(tab: &mut Tab) -> Result<()> { - if let Display::Directory | Display::Tree = tab.display_mode { - tab.filepath_to_clipboard(); + pub fn copy_filepath(status: &Status) -> Result<()> { + match status.current_tab().display_mode { + Display::Tree | Display::Directory => { + let Ok(file_info) = status.current_tab().current_file() else { + return Ok(()); + }; + filepath_to_clipboard(&file_info.path); + } + Display::Flagged => { + let Some(path) = status.menu.flagged.selected() else { + return Ok(()); + }; + filepath_to_clipboard(&path); + } + _ => return Ok(()), } Ok(()) } |