diff --git a/src/keymaps.rs b/src/keymaps.rs index ce9a0d9..1334f4b 100644 --- a/src/keymaps.rs +++ b/src/keymaps.rs @@ -27,11 +27,13 @@ use clipboard::{ClipboardContext, ClipboardProvider}; pub fn pressed_enter(app: &mut App) { let secrets_panel = app.panels.get(&PanelName::Secrets).unwrap(); let selected_index = secrets_panel.index; - let secret_name = &secrets_panel.content[selected_index]; - let secret = utils::get_secret(&secret_name, &utils::get_secret_file_path()).unwrap(); - // 复制到剪贴板 - let mut clipboard = ClipboardContext::new().unwrap(); - clipboard.set_contents(secret).unwrap(); + if secrets_panel.content.len() > 0 { + let secret_name = &secrets_panel.content[selected_index]; + let secret = utils::get_secret(&secret_name, &utils::get_secret_file_path()).unwrap(); + // 复制到剪贴板 + let mut clipboard = ClipboardContext::new().unwrap(); + clipboard.set_contents(secret).unwrap(); + } } pub fn move_cursor_vertical(app: &mut App, step: i8) { @@ -41,4 +43,4 @@ pub fn move_cursor_vertical(app: &mut App, step: i8) { } else if step == -1 && secrets_panel.index > 0 { secrets_panel.index -= 1; } -} +} \ No newline at end of file