Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(layout): tab focus #2197

Merged
merged 2 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zellij-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, 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();
}
Expand Down
28 changes: 23 additions & 5 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,10 @@ pub(crate) fn screen_thread_main(
copy_options,
);

let mut pending_tab_ids: HashSet<usize> = 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
Expand Down Expand Up @@ -1998,6 +2002,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
Expand Down Expand Up @@ -2029,11 +2034,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
Expand All @@ -2043,10 +2054,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) => {
Expand Down