From e2b4e12cf1ce15a26172ac8f2166c5e02ca89351 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sat, 5 Jul 2025 22:55:46 +0200 Subject: quit creating note function if citekey contains special char --- src/app.rs | 24 ++++++++++++++++++++++-- src/bibiman.rs | 7 +++++-- 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/app.rs b/src/app.rs index 01424bc..708ec37 100644 --- a/src/app.rs +++ b/src/app.rs @@ -427,7 +427,27 @@ impl App { } CmdAction::CreateNote => { if let CurrentArea::EntryArea = self.bibiman.current_area { - if cfg.general.note_path.is_some() + let citekey = self.bibiman.entry_table.entry_table_items[self + .bibiman + .entry_table + .entry_table_state + .selected() + .unwrap()] + .citekey + .clone(); + if citekey.contains("/") + | citekey.contains("|") + | citekey.contains("#") + | citekey.contains("\\") + | citekey.contains("*") + { + self.bibiman.open_popup( + PopupKind::MessageError, + Some("Selected entrys citekey contains special char: "), + Some(&citekey), + None, + )?; + } else if cfg.general.note_path.is_some() && cfg.general.note_extensions.is_some() && self.bibiman.entry_table.entry_table_items[self .bibiman @@ -454,7 +474,7 @@ impl App { )); } self.bibiman - .open_popup(PopupKind::CreateNote, None, None, Some(items)); + .open_popup(PopupKind::CreateNote, None, None, Some(items))?; } else if cfg.general.note_path.is_some() && self.bibiman.entry_table.entry_table_items[self .bibiman diff --git a/src/bibiman.rs b/src/bibiman.rs index 87963dc..6d21f8c 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -755,13 +755,15 @@ impl Bibiman { pub fn create_note(&mut self, cfg: &BibiConfig) -> Result<()> { // Index of selected entry let entry_idx = self.entry_table.entry_table_state.selected().unwrap(); - let citekey = self.entry_table.entry_table_items[entry_idx].citekey(); + let citekey = self.entry_table.entry_table_items[entry_idx] + .citekey + .clone(); // Index of selected popup field let popup_idx = self.popup_area.popup_state.selected().unwrap(); let ext = self.popup_area.popup_list[popup_idx].1.clone(); - let basename = PathBuf::from(citekey).with_extension(ext); + let basename = PathBuf::from(&citekey).with_extension(ext); let path = cfg.general.note_path.as_ref().unwrap(); let new_file = path.join(basename); @@ -775,6 +777,7 @@ impl Bibiman { File::create_new(new_file).unwrap(); self.close_popup(); self.update_lists(cfg); + self.select_entry_by_citekey(&citekey); Ok(()) } -- cgit v1.2.3