From b2e901ecd38f20b281a4a584a21bf2fc1b83e24b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 15 Oct 2022 08:55:11 -0700 Subject: [PATCH] launcher: don't panic when launching nothing refs: https://github.com/wez/wezterm/issues/2629 --- docs/changelog.md | 2 ++ wezterm-gui/src/overlay/launcher.rs | 32 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index ecfce75d6..d7f5c3050 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -92,6 +92,8 @@ As features stabilize some brief notes about them will accumulate here. [#2568](https://github.com/wez/wezterm/issues/2568) * Incorrect shaping for U+28 U+FF9F [#2572](https://github.com/wez/wezterm/issues/2572) +* Panic when hitting enter in launcher menu when no fuzzy results match + [#2629](https://github.com/wez/wezterm/issues/2629) #### Changed * Removed Last Resort fallback font diff --git a/wezterm-gui/src/overlay/launcher.rs b/wezterm-gui/src/overlay/launcher.rs index 19e0d525d..3fd3a3bb2 100644 --- a/wezterm-gui/src/overlay/launcher.rs +++ b/wezterm-gui/src/overlay/launcher.rs @@ -411,12 +411,17 @@ impl LauncherState { term.render(&changes) } - fn launch(&self, active_idx: usize) { - let assignment = self.filtered_entries[active_idx].action.clone(); - self.window.notify(TermWindowNotif::PerformAssignment { - pane_id: self.pane_id, - assignment, - }); + fn launch(&self, active_idx: usize) -> bool { + if let Some(entry) = self.filtered_entries.get(active_idx) { + let assignment = entry.action.clone(); + self.window.notify(TermWindowNotif::PerformAssignment { + pane_id: self.pane_id, + assignment, + }); + true + } else { + false + } } fn move_up(&mut self) { @@ -440,8 +445,9 @@ impl LauncherState { key: KeyCode::Char(c), .. }) if !self.filtering && c >= '1' && c <= '9' => { - self.launch(self.top_row + (c as u32 - '1' as u32) as usize); - break; + if self.launch(self.top_row + (c as u32 - '1' as u32) as usize) { + break; + } } InputEvent::Key(KeyEvent { key: KeyCode::Char('j'), @@ -538,8 +544,9 @@ impl LauncherState { self.active_idx = self.top_row + y as usize - 1; if mouse_buttons == MouseButtons::LEFT { - self.launch(self.active_idx); - break; + if self.launch(self.active_idx) { + break; + } } } if mouse_buttons != MouseButtons::NONE { @@ -551,8 +558,9 @@ impl LauncherState { key: KeyCode::Enter, .. }) => { - self.launch(self.active_idx); - break; + if self.launch(self.active_idx) { + break; + } } InputEvent::Resized { rows, .. } => { self.max_items = rows.saturating_sub(ROW_OVERHEAD);