From 0874e09c3108816ee8b49a849e30f5dbce2a5d6e Mon Sep 17 00:00:00 2001 From: Ivordir Date: Sat, 15 Apr 2023 15:11:04 +0000 Subject: [PATCH] Fix out of bounds panic (#16) --- anyrun/src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/anyrun/src/main.rs b/anyrun/src/main.rs index 8bfc972..725ab86 100644 --- a/anyrun/src/main.rs +++ b/anyrun/src/main.rs @@ -390,14 +390,16 @@ fn activate(app: >k::Application, runtime_data: Rc Some(selected) => selected, None => { // If nothing is selected select either the top or bottom match based on the input - match event.keyval() { - constants::Down | constants::Tab => combined_matches[0] - .1 - .select_row(Some(&combined_matches[0].0)), - constants::Up => combined_matches[combined_matches.len() - 1] - .1 - .select_row(Some(&combined_matches[combined_matches.len() - 1].0)), - _ => unreachable!(), + if !combined_matches.is_empty() { + match event.keyval() { + constants::Down | constants::Tab => combined_matches[0] + .1 + .select_row(Some(&combined_matches[0].0)), + constants::Up => combined_matches[combined_matches.len() - 1] + .1 + .select_row(Some(&combined_matches[combined_matches.len() - 1].0)), + _ => unreachable!(), + } } return Inhibit(true); }