diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.rs | 4 | ||||
| -rw-r--r-- | src/bibiman.rs | 71 | ||||
| -rw-r--r-- | src/tui/ui.rs | 10 |
3 files changed, 84 insertions, 1 deletions
@@ -79,6 +79,10 @@ impl App { } else if let Some(PopupKind::MessageError) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup() + } else if let Some(PopupKind::YankItem) | Some(PopupKind::OpenRes) = + self.bibiman.popup_area.popup_kind + { + self.bibiman.fast_selection(cfg, key_event.code)?; } let command = if self.input_mode { CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) 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(); diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 7a121bf..ebebe4c 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -299,9 +299,17 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { " Select " }; + let bottom_info = if let Some(PopupKind::OpenRes) = app.bibiman.popup_area.popup_kind { + " (j,k|↓,↑) ━ (o,l) ━ (ENTER) ━ (ESC) ".bold() + } else if let Some(PopupKind::YankItem) = app.bibiman.popup_area.popup_kind { + " (j,k|↓,↑) ━ (y) ━ (ENTER) ━ (ESC) ".bold() + } else { + " (j,k|↓,↑) ━ (ENTER) ━ (ESC) ".bold() + }; + let block = Block::bordered() .title_top(title.bold()) - .title_bottom(" (j,k|↓,↑) ━ (ENTER) ━ (ESC) ".bold()) + .title_bottom(bottom_info) .title_alignment(Alignment::Center) .style( Style::new() |
