Select active tab choice as initial choice in ShowTabNavigator (#6320)

* Select current tab option as initial choice in ShowTabNavigator

This introduces the following changes
- Select the choice corresponding to the active tab as the initial choice

* docs: Add current tab choice documentation in ShowTabNavigator

This changes the following
- Update ShowTabNavigator.md with current tab choice documentation

* refactor: remove redundant local variable
This commit is contained in:
mgpinf authored and GitHub committed 2025-02-08 14:43:34 -07:00
1 parent 656e62541f
commit f55293262e
3 files changed
+15 -5

No files matched your search

@@ -10,4 +10,7 @@ config.keys = {
}
```
{{since('nightly')}}
The choice corresponding to the current tab is initially selected.
+2 -1
View File
@@ -593,11 +593,12 @@ pub fn launcher(
args: LauncherArgs,
mut term: TermWizTerminal,
window: ::window::Window,
initial_choice_idx: usize,
) -> anyhow::Result<()> {
let size = term.get_screen_size()?;
let max_items = size.rows.saturating_sub(ROW_OVERHEAD);
let mut state = LauncherState {
active_idx: 0,
active_idx: initial_choice_idx,
max_items,
pane_id: args.pane_id,
top_row: 0,
+10 -4
View File
@@ -2328,7 +2328,12 @@ impl TermWindow {
}
fn show_tab_navigator(&mut self) {
self.show_launcher_impl("Tab Navigator", LauncherFlags::TABS);
let mux = Mux::get();
let active_tab_idx = match mux.get_window(self.mux_window_id) {
Some(mux_window) => mux_window.get_active_idx(),
None => return,
};
self.show_launcher_impl("Tab Navigator", LauncherFlags::TABS, active_tab_idx);
}
fn show_launcher(&mut self) {
@@ -2339,10 +2344,11 @@ impl TermWindow {
| LauncherFlags::DOMAINS
| LauncherFlags::KEY_ASSIGNMENTS
| LauncherFlags::COMMANDS,
0,
);
}
fn show_launcher_impl(&mut self, title: &str, flags: LauncherFlags) {
fn show_launcher_impl(&mut self, title: &str, flags: LauncherFlags, initial_choice_idx: usize) {
let mux_window_id = self.mux_window_id;
let window = self.window.as_ref().unwrap().clone();
@@ -2382,7 +2388,7 @@ impl TermWindow {
let window = window.clone();
let (overlay, future) =
start_overlay(term_window, &tab, move |_tab_id, term| {
launcher(args, term, window)
launcher(args, term, window, initial_choice_idx)
});
term_window.assign_overlay(tab_id, overlay);
@@ -2706,7 +2712,7 @@ impl TermWindow {
ShowDebugOverlay => self.show_debug_overlay(),
ShowLauncher => self.show_launcher(),
ShowLauncherArgs(args) => {
self.show_launcher_impl(args.title.as_deref().unwrap_or("Launcher"), args.flags)
self.show_launcher_impl(args.title.as_deref().unwrap_or("Launcher"), args.flags, 0)
}
HideApplication => {
let con = Connection::get().expect("call on gui thread");