Skip to content

Commit

Permalink
feat(tabs): add command for closing all tabs except the current one (#…
Browse files Browse the repository at this point in the history
…614)

* feat(tabs): add command for closing all tabs except the current one (`closeothertabs`)

* refactor(tabs): apply review suggestions
  • Loading branch information
orhun authored Aug 27, 2024
1 parent 3e80417 commit 2c5a402
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions docs/docs/key-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Execute a predefined action in Rio terminal.
| :------------------- | :------------------------------------------------------------------ |
| CreateTab | |
| CloseTab | |
| CloseUnfocusedTabs | |
| SelectPrevTab | |
| SelectNextTab | |
| SelectLastTab | |
Expand Down
4 changes: 4 additions & 0 deletions frontends/rioterm/src/bindings/bindings_winit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions frontends/rioterm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 2c5a402

Please sign in to comment.