From 82389ef5b3337f6bcd4236d3dd86923f434c6119 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 1 Jan 2026 04:57:15 +0200 Subject: [PATCH] fix: prevent panic when switching to non-existent tab --- src/app/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index a6a88ab..a285fea 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -124,11 +124,13 @@ impl App { self.index = self.index.checked_sub(1).unwrap_or(self.tabs.len() - 1); } - /// Switches to the tab whose index is `idx`. + /// Switches to the tab whose index is `idx` if it exists. #[inline] - pub const fn switch_tab(&mut self, idx: usize) { - self.close_help(); - self.index = idx; + pub fn switch_tab(&mut self, idx: usize) { + if idx < self.tabs.len() { + self.close_help(); + self.index = idx; + } } /// Returns current active [`Tab`] number