fix(tabs): maintain event order for MoveTab (#3758)

* fix(tabs): maintain event order for MoveTab

* style(fmt): rustfmt
This commit is contained in:
Aram Drevekenin 2024-11-11 16:30:03 +01:00 committed by GitHub
parent c13fda444c
commit 942b435a67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 59 deletions

View file

@ -262,7 +262,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
pty.bus.senders.clone(), pty.bus.senders.clone(),
*terminal_id, *terminal_id,
run_command.clone(), run_command.clone(),
None,
) )
.with_context(err_context)?; .with_context(err_context)?;
} }
@ -342,7 +341,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
pty.bus.senders.clone(), pty.bus.senders.clone(),
*terminal_id, *terminal_id,
run_command.clone(), run_command.clone(),
None,
) )
.with_context(err_context)?; .with_context(err_context)?;
} }
@ -445,8 +443,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
PaneId::Terminal(*terminal_id), PaneId::Terminal(*terminal_id),
Some(2), // exit status Some(2), // exit status
run_command, run_command,
None,
None,
)) ))
.with_context(err_context)?; .with_context(err_context)?;
} }
@ -516,8 +512,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
PaneId::Terminal(*terminal_id), PaneId::Terminal(*terminal_id),
Some(2), // exit status Some(2), // exit status
run_command, run_command,
None,
None,
)) ))
.with_context(err_context)?; .with_context(err_context)?;
} }
@ -614,8 +608,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
PaneId::Terminal(*terminal_id), PaneId::Terminal(*terminal_id),
Some(2), // exit status Some(2), // exit status
run_command, run_command,
None,
None,
)) ))
.with_context(err_context)?; .with_context(err_context)?;
} }
@ -667,8 +659,6 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
PaneId::Terminal(*terminal_id), PaneId::Terminal(*terminal_id),
Some(2), // exit status Some(2), // exit status
run_command, run_command,
None,
None,
)) ))
.with_context(err_context)?; .with_context(err_context)?;
} }
@ -985,8 +975,6 @@ impl Pty {
pane_id, pane_id,
exit_status, exit_status,
command, command,
None,
None,
)); ));
} else { } else {
let _ = senders.send_to_screen(ScreenInstruction::ClosePane(pane_id, None)); let _ = senders.send_to_screen(ScreenInstruction::ClosePane(pane_id, None));
@ -1059,14 +1047,14 @@ impl Pty {
// new_pane_pids // new_pane_pids
for run_instruction in extracted_run_instructions { for run_instruction in extracted_run_instructions {
if let Some(new_pane_data) = 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); new_pane_pids.push(new_pane_data);
} }
} }
for run_instruction in extracted_floating_run_instructions { for run_instruction in extracted_floating_run_instructions {
if let Some(new_pane_data) = 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); new_floating_panes_pids.push(new_pane_data);
} }
@ -1147,7 +1135,6 @@ impl Pty {
self.bus.senders.clone(), self.bus.senders.clone(),
terminal_id, terminal_id,
run_command.clone(), run_command.clone(),
Some(tab_index),
) )
.with_context(err_context)?; .with_context(err_context)?;
} else { } else {
@ -1168,7 +1155,6 @@ impl Pty {
&mut self, &mut self,
run_instruction: Option<Run>, run_instruction: Option<Run>,
default_shell: TerminalAction, default_shell: TerminalAction,
tab_index: usize,
) -> Result<Option<(u32, bool, Option<RunCommand>, Result<i32>)>> { ) -> Result<Option<(u32, bool, Option<RunCommand>, Result<i32>)>> {
// terminal_id, // terminal_id,
// starts_held, // starts_held,
@ -1193,8 +1179,6 @@ impl Pty {
pane_id, pane_id,
exit_status, exit_status,
command, command,
Some(tab_index),
None,
)); ));
} else { } else {
let _ = let _ =
@ -1425,8 +1409,6 @@ impl Pty {
pane_id, pane_id,
exit_status, exit_status,
command, command,
None,
None,
)); ));
} else { } else {
let _ = let _ =
@ -1598,7 +1580,6 @@ fn send_command_not_found_to_screen(
senders: ThreadSenders, senders: ThreadSenders,
terminal_id: u32, terminal_id: u32,
run_command: RunCommand, run_command: RunCommand,
tab_index: Option<usize>,
) -> Result<()> { ) -> Result<()> {
let err_context = || format!("failed to send command_not_fount for terminal {terminal_id}"); let err_context = || format!("failed to send command_not_fount for terminal {terminal_id}");
senders senders
@ -1614,8 +1595,6 @@ fn send_command_not_found_to_screen(
PaneId::Terminal(terminal_id), PaneId::Terminal(terminal_id),
Some(2), Some(2),
run_command.clone(), run_command.clone(),
tab_index,
None,
)) ))
.with_context(err_context)?; .with_context(err_context)?;
Ok(()) Ok(())

View file

@ -202,13 +202,7 @@ pub enum ScreenInstruction {
TogglePaneFrames, TogglePaneFrames,
SetSelectable(PaneId, bool), SetSelectable(PaneId, bool),
ClosePane(PaneId, Option<ClientId>), ClosePane(PaneId, Option<ClientId>),
HoldPane( HoldPane(PaneId, Option<i32>, RunCommand),
PaneId,
Option<i32>,
RunCommand,
Option<usize>,
Option<ClientId>,
), // Option<i32> is the exit status, Option<usize> is the tab_index
UpdatePaneName(Vec<u8>, ClientId), UpdatePaneName(Vec<u8>, ClientId),
UndoRenamePane(ClientId), UndoRenamePane(ClientId),
NewTab( NewTab(
@ -3355,33 +3349,14 @@ pub(crate) fn screen_thread_main(
screen.unblock_input()?; screen.unblock_input()?;
screen.log_and_report_session_state()?; 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; 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() { for tab in screen.tabs.values_mut() {
if tab.get_all_pane_ids().contains(&id) { if tab.get_all_pane_ids().contains(&id) {
tab.hold_pane(id, exit_status, is_first_run, run_command); tab.hold_pane(id, exit_status, is_first_run, run_command);
break; break;
} }
} }
},
}
screen.unblock_input()?; screen.unblock_input()?;
screen.log_and_report_session_state()?; screen.log_and_report_session_state()?;
}, },
@ -3635,14 +3610,22 @@ pub(crate) fn screen_thread_main(
screen.render(None)?; screen.render(None)?;
}, },
ScreenInstruction::MoveTabLeft(client_id) => { ScreenInstruction::MoveTabLeft(client_id) => {
if pending_tab_ids.is_empty() {
screen.move_active_tab_to_left(client_id)?; screen.move_active_tab_to_left(client_id)?;
screen.unblock_input()?;
screen.render(None)?; screen.render(None)?;
} else {
pending_events_waiting_for_tab.push(ScreenInstruction::MoveTabLeft(client_id));
}
screen.unblock_input()?;
}, },
ScreenInstruction::MoveTabRight(client_id) => { ScreenInstruction::MoveTabRight(client_id) => {
if pending_tab_ids.is_empty() {
screen.move_active_tab_to_right(client_id)?; screen.move_active_tab_to_right(client_id)?;
screen.unblock_input()?;
screen.render(None)?; screen.render(None)?;
} else {
pending_events_waiting_for_tab.push(ScreenInstruction::MoveTabRight(client_id));
}
screen.unblock_input()?;
}, },
ScreenInstruction::TerminalResize(new_size) => { ScreenInstruction::TerminalResize(new_size) => {
screen.resize_to_screen(new_size)?; screen.resize_to_screen(new_size)?;