From 942b435a67eac8c9c1766cd44bf95374e73ce634 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 11 Nov 2024 16:30:03 +0100 Subject: [PATCH] fix(tabs): maintain event order for MoveTab (#3758) * fix(tabs): maintain event order for MoveTab * style(fmt): rustfmt --- zellij-server/src/pty.rs | 25 ++--------------- zellij-server/src/screen.rs | 55 +++++++++++++------------------------ 2 files changed, 21 insertions(+), 59 deletions(-) diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index da5bd7bd..dc9e5809 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -262,7 +262,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box) -> Result<()> { pty.bus.senders.clone(), *terminal_id, run_command.clone(), - None, ) .with_context(err_context)?; } @@ -342,7 +341,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box) -> Result<()> { pty.bus.senders.clone(), *terminal_id, run_command.clone(), - None, ) .with_context(err_context)?; } @@ -445,8 +443,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box) -> Result<()> { PaneId::Terminal(*terminal_id), Some(2), // exit status run_command, - None, - None, )) .with_context(err_context)?; } @@ -516,8 +512,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box) -> Result<()> { PaneId::Terminal(*terminal_id), Some(2), // exit status run_command, - None, - None, )) .with_context(err_context)?; } @@ -614,8 +608,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box) -> Result<()> { PaneId::Terminal(*terminal_id), Some(2), // exit status run_command, - None, - None, )) .with_context(err_context)?; } @@ -667,8 +659,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box) -> Result<()> { PaneId::Terminal(*terminal_id), Some(2), // exit status run_command, - None, - None, )) .with_context(err_context)?; } @@ -985,8 +975,6 @@ impl Pty { pane_id, exit_status, command, - None, - None, )); } else { let _ = senders.send_to_screen(ScreenInstruction::ClosePane(pane_id, None)); @@ -1059,14 +1047,14 @@ impl Pty { // new_pane_pids for run_instruction in extracted_run_instructions { if let Some(new_pane_data) = - self.apply_run_instruction(run_instruction, default_shell.clone(), tab_index)? + self.apply_run_instruction(run_instruction, default_shell.clone())? { new_pane_pids.push(new_pane_data); } } for run_instruction in extracted_floating_run_instructions { if let Some(new_pane_data) = - self.apply_run_instruction(run_instruction, default_shell.clone(), tab_index)? + self.apply_run_instruction(run_instruction, default_shell.clone())? { new_floating_panes_pids.push(new_pane_data); } @@ -1147,7 +1135,6 @@ impl Pty { self.bus.senders.clone(), terminal_id, run_command.clone(), - Some(tab_index), ) .with_context(err_context)?; } else { @@ -1168,7 +1155,6 @@ impl Pty { &mut self, run_instruction: Option, default_shell: TerminalAction, - tab_index: usize, ) -> Result, Result)>> { // terminal_id, // starts_held, @@ -1193,8 +1179,6 @@ impl Pty { pane_id, exit_status, command, - Some(tab_index), - None, )); } else { let _ = @@ -1425,8 +1409,6 @@ impl Pty { pane_id, exit_status, command, - None, - None, )); } else { let _ = @@ -1598,7 +1580,6 @@ fn send_command_not_found_to_screen( senders: ThreadSenders, terminal_id: u32, run_command: RunCommand, - tab_index: Option, ) -> Result<()> { let err_context = || format!("failed to send command_not_fount for terminal {terminal_id}"); senders @@ -1614,8 +1595,6 @@ fn send_command_not_found_to_screen( PaneId::Terminal(terminal_id), Some(2), run_command.clone(), - tab_index, - None, )) .with_context(err_context)?; Ok(()) diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index a1e1407e..174d712c 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -202,13 +202,7 @@ pub enum ScreenInstruction { TogglePaneFrames, SetSelectable(PaneId, bool), ClosePane(PaneId, Option), - HoldPane( - PaneId, - Option, - RunCommand, - Option, - Option, - ), // Option is the exit status, Option is the tab_index + HoldPane(PaneId, Option, RunCommand), UpdatePaneName(Vec, ClientId), UndoRenamePane(ClientId), NewTab( @@ -3355,32 +3349,13 @@ pub(crate) fn screen_thread_main( screen.unblock_input()?; screen.log_and_report_session_state()?; }, - ScreenInstruction::HoldPane(id, exit_status, run_command, tab_index, client_id) => { + ScreenInstruction::HoldPane(id, exit_status, run_command) => { let is_first_run = false; - match (client_id, tab_index) { - (Some(client_id), _) => { - active_tab!(screen, client_id, |tab: &mut Tab| tab.hold_pane( - id, - exit_status, - is_first_run, - run_command - )); - }, - (_, Some(tab_index)) => match screen.tabs.get_mut(&tab_index) { - Some(tab) => tab.hold_pane(id, exit_status, is_first_run, run_command), - None => log::warn!( - "Tab with index {tab_index} not found. Cannot hold pane with id {:?}", - id - ), - }, - _ => { - for tab in screen.tabs.values_mut() { - if tab.get_all_pane_ids().contains(&id) { - tab.hold_pane(id, exit_status, is_first_run, run_command); - break; - } - } - }, + for tab in screen.tabs.values_mut() { + if tab.get_all_pane_ids().contains(&id) { + tab.hold_pane(id, exit_status, is_first_run, run_command); + break; + } } screen.unblock_input()?; screen.log_and_report_session_state()?; @@ -3635,14 +3610,22 @@ pub(crate) fn screen_thread_main( screen.render(None)?; }, ScreenInstruction::MoveTabLeft(client_id) => { - screen.move_active_tab_to_left(client_id)?; + if pending_tab_ids.is_empty() { + screen.move_active_tab_to_left(client_id)?; + screen.render(None)?; + } else { + pending_events_waiting_for_tab.push(ScreenInstruction::MoveTabLeft(client_id)); + } screen.unblock_input()?; - screen.render(None)?; }, ScreenInstruction::MoveTabRight(client_id) => { - screen.move_active_tab_to_right(client_id)?; + if pending_tab_ids.is_empty() { + screen.move_active_tab_to_right(client_id)?; + screen.render(None)?; + } else { + pending_events_waiting_for_tab.push(ScreenInstruction::MoveTabRight(client_id)); + } screen.unblock_input()?; - screen.render(None)?; }, ScreenInstruction::TerminalResize(new_size) => { screen.resize_to_screen(new_size)?;