From 6a2a845086386c5be71ef35d16ea63b2c21708b7 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Sun, 26 Feb 2023 19:20:49 +0100 Subject: [PATCH] fix(layout): tab focus (#2197) * fix(layout): tab focus * style(fmt): rustfmt --- zellij-server/src/lib.rs | 4 ++-- zellij-server/src/screen.rs | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index f095e0c6..5dc728fb 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -385,9 +385,9 @@ pub fn start_server(mut os_input: Box, socket_path: PathBuf) { .as_ref() .unwrap() .senders - .send_to_pty(PtyInstruction::GoToTab( + .send_to_screen(ScreenInstruction::GoToTab( (focused_tab_index + 1) as u32, - client_id, + Some(client_id), )) .unwrap(); } diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index eb0d359a..97acc0fd 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -1413,6 +1413,10 @@ pub(crate) fn screen_thread_main( copy_options, ); + let mut pending_tab_ids: HashSet = HashSet::new(); + let mut pending_tab_switches: HashSet<(usize, ClientId)> = HashSet::new(); // usize is the + // tab_index + loop { let (event, mut err_ctx) = screen .bus @@ -2011,6 +2015,7 @@ pub(crate) fn screen_thread_main( client_id, ) => { let tab_index = screen.get_new_tab_index(); + pending_tab_ids.insert(tab_index); screen.new_tab(tab_index, swap_layouts, client_id)?; screen .bus @@ -2042,11 +2047,17 @@ pub(crate) fn screen_thread_main( tab_index, client_id, )?; + pending_tab_ids.remove(&tab_index); + if pending_tab_ids.is_empty() { + for (tab_index, client_id) in pending_tab_switches.drain() { + screen.go_to_tab(tab_index as usize, client_id)?; + } + } screen.unblock_input()?; screen.render()?; }, ScreenInstruction::GoToTab(tab_index, client_id) => { - let client_id = if client_id.is_none() { + let client_id_to_switch = if client_id.is_none() { None } else if screen .active_tab_indices @@ -2056,10 +2067,17 @@ pub(crate) fn screen_thread_main( } else { screen.active_tab_indices.keys().next().copied() }; - if let Some(client_id) = client_id { - screen.go_to_tab(tab_index as usize, client_id)?; - screen.unblock_input()?; - screen.render()?; + match client_id_to_switch { + Some(client_id) => { + screen.go_to_tab(tab_index as usize, client_id)?; + screen.unblock_input()?; + screen.render()?; + }, + None => { + if let Some(client_id) = client_id { + pending_tab_switches.insert((tab_index as usize, client_id)); + } + }, } }, ScreenInstruction::GoToTabName(tab_name, swap_layouts, create, client_id) => {