diff options
Diffstat (limited to 'src/bibiman.rs')
| -rw-r--r-- | src/bibiman.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs index 3341653..71ef07c 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -26,6 +26,7 @@ use crate::{app, cliargs}; use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList}; use arboard::Clipboard; use color_eyre::eyre::{Error, Result}; +use crossterm::event::{KeyCode, KeyEvent}; use editor_command::EditorBuilder; use ratatui::widgets::ScrollbarState; use regex::Regex; @@ -725,6 +726,76 @@ impl Bibiman { Ok(()) } + /// Fast opening/yanking of file/link or citekey through simple keypress in + /// the particular popup mode: + /// + /// **Opening popup** + /// + /// `o` -> opens the first file of the `filepath` `Vec` for the current entry + /// `l` -> opens the link of the current entry + /// + /// **Yanking popup** + /// + /// `y` -> yanks the citekey for the current entry + pub fn fast_selection(&mut self, cfg: &BibiConfig, key_code: KeyCode) -> Result<()> { + if let CurrentArea::PopupArea = self.current_area { + let entry_idx = self.entry_table.entry_table_state.selected().unwrap(); + match self.popup_area.popup_kind { + Some(PopupKind::OpenRes) => match key_code { + KeyCode::Char('o') => { + let file = self.entry_table.entry_table_items[entry_idx] + .filepath + .clone(); + if file.is_some() { + let file = expand_home(&PathBuf::from(file.unwrap()[0].clone())); + // let object: OsString = popup_entry.into(); + if file.is_file() { + app::open_connected_file(cfg, &file.into_os_string())?; + self.close_popup(); + } else { + self.open_popup( + PopupKind::MessageError, + Some("No valid file path: "), + Some(file.to_str().unwrap()), + None, + )?; + } + } + } + KeyCode::Char('l') => { + if self.entry_table.entry_table_items[entry_idx] + .doi_url + .is_some() + { + let object = self.entry_table.entry_table_items[entry_idx].doi_url(); + let url = app::prepare_weblink(object); + app::open_connected_link(cfg, &url)?; + self.close_popup(); + } + } + _ => {} + }, + Some(PopupKind::YankItem) => match key_code { + KeyCode::Char('y') => { + let key = self.entry_table.entry_table_items[entry_idx] + .citekey + .clone(); + Bibiman::yank_text(&key); + self.open_popup( + PopupKind::MessageConfirm, + Some("Yanked citekey to clipboard: "), + Some(&key), + None, + )?; + } + _ => {} + }, + _ => {} + } + } + Ok(()) + } + /// Formats a raw BibTeX entry string for better readability. pub fn format_bibtex_entry(entry: &str, file_path: &str) -> String { let mut formatted = String::new(); |
