Repository: raphamorim/rio (language: rust)

Issue:
Close all tabs except for the curent one 
Close all tabs except for the curent one 


Discussion / hints:
Happy to add this feature if @raphamorim finds it useful :)
I think this feature makes sense but I don’t think it can be via UI at least now. Either will be a Action that you can configure through key binding like `CloseAllBesidesCurrent` or a cli hook. However the second option will require build the cli support to trigger on Rio application. So maybe start with key binding now?
Thank you very much for your project. The UI is not necessary; implementing an action and binding it to a shortcut key would be perfect
Alright, I will be working on it then 🐻 

Fix patch:
diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md
index f69c13a02b..555547c13d 100644
--- a/docs/docs/changelog.md
+++ b/docs/docs/changelog.md
@@ -18,6 +18,7 @@ language: 'en'
 - Fix: Mouse pointer hidden (Ubuntu Wayland) / Cursor icon not changing [#383](https://github.com/raphamorim/rio/issues/383).
 - `use-kitty-keyboard-protocol` is now `true` as default.
 - Enable search functionality as default on Linux.
+- Add command for closing all tabs except the current one (`closeunfocusedtabs`)
 
 ## 0.1.9
 
diff --git a/docs/docs/key-bindings.md b/docs/docs/key-bindings.md
index a365f44ccc..0be32dd26e 100644
--- a/docs/docs/key-bindings.md
+++ b/docs/docs/key-bindings.md
@@ -194,6 +194,7 @@ Execute a predefined action in Rio terminal.
 | :------------------- | :------------------------------------------------------------------ |
 | CreateTab            |                                                                     |
 | CloseTab             |                                                                     |
+| CloseUnfocusedTabs   |                                                                     |
 | SelectPrevTab        |                                                                     |
 | SelectNextTab        |                                                                     |
 | SelectLastTab        |                                                                     |
diff --git a/frontends/rioterm/src/bindings/bindings_winit/mod.rs b/frontends/rioterm/src/bindings/bindings_winit/mod.rs
index 3bc649e874..4188395414 100644
--- a/frontends/rioterm/src/bindings/bindings_winit/mod.rs
+++ b/frontends/rioterm/src/bindings/bindings_winit/mod.rs
@@ -237,6 +237,7 @@ impl From<String> for Action {
             "createwindow" => Some(Action::WindowCreateNew),
             "createtab" => Some(Action::TabCreateNew),
             "closetab" => Some(Action::TabCloseCurrent),
+            "closeunfocusedtabs" => Some(Action::TabCloseUnfocused),
             "openconfigeditor" => Some(Action::ConfigEditor),
             "selectprevtab" => Some(Action::SelectPrevTab),
             "selectnexttab" => Some(Action::SelectNextTab),
@@ -409,6 +410,9 @@ pub enum Action {
     /// Close tab.
     TabCloseCurrent,
 
+    /// Close all other tabs (leave only the current tab).
+    TabCloseUnfocused,
+
     /// Toggle fullscreen.
     #[allow(dead_code)]
     ToggleFullscreen,
diff --git a/frontends/rioterm/src/context.rs b/frontends/rioterm/src/context.rs
index 1ca6186817..a47ef942aa 100644
--- a/frontends/rioterm/src/context.rs
+++ b/frontends/rioterm/src/context.rs
@@ -435,6 +435,15 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
             .send_event(RioEvent::CreateWindow, self.window_id);
     }
 
+    #[inline]
+    pub fn close_unfocused_tabs(&mut self) {
+        let current_route_id = self.current().route_id;
+        self.titles.titles.retain(|&i, _| i == self.current_index);
+        self.contexts.retain(|ctx| ctx.route_id == current_route_id);
+        self.current_route = self.contexts[0].route_id;
+        self.set_current(0);
+    }
+
     #[inline]
     pub fn select_tab(&mut self, tab_index: usize) {
         if self.config.is_native {
diff --git a/frontends/rioterm/src/screen/mod.rs b/frontends/rioterm/src/screen/mod.rs
index a9856f56a8..e0559660f3 100644
--- a/frontends/rioterm/src/screen/mod.rs
+++ b/frontends/rioterm/src/screen/mod.rs
@@ -828,6 +828,16 @@ impl Screen<'_> {
                         self.resize_top_or_bottom_line(num_tabs);
                         self.demand_render();
                     }
+                    Act::TabCloseUnfocused => {
+                        self.clear_selection();
+                        self.cancel_search();
+                        if self.ctx().len() <= 1 {
+                            return true;
+                        }
+                        self.context_manager.close_unfocused_tabs();
+                        self.resize_top_or_bottom_line(1);
+                        self.demand_render();
+                    }
                     Act::Quit => {
                         self.context_manager.quit();
                     }


Test patch: