Keep SSH pane focus and visible grids in sync
This commit is contained in:
+1
-1
@@ -409,7 +409,7 @@ fn shell_quote(value: &str) -> String {
|
|||||||
format!("'{}'", value.replace('\'', "'\\''"))
|
format!("'{}'", value.replace('\'', "'\\''"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_snapshot(snapshot: &Snapshot) -> Result<()> {
|
pub(crate) fn validate_snapshot(snapshot: &Snapshot) -> Result<()> {
|
||||||
if snapshot.tabs.len() > 256 || snapshot.lineage.len() > 256 || snapshot.panes.len() > 64 {
|
if snapshot.tabs.len() > 256 || snapshot.lineage.len() > 256 || snapshot.panes.len() > 64 {
|
||||||
bail!("Server layout exceeds client limits");
|
bail!("Server layout exceeds client limits");
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -1194,17 +1194,20 @@ impl SessionState {
|
|||||||
fn snapshot(&mut self) -> Snapshot {
|
fn snapshot(&mut self) -> Snapshot {
|
||||||
self.update_titles();
|
self.update_titles();
|
||||||
self.revision += 1;
|
self.revision += 1;
|
||||||
|
let mut tabs = self.tabs.clone();
|
||||||
if let Some(remote) = self
|
if let Some(remote) = self
|
||||||
.remotes
|
.remotes
|
||||||
.values()
|
.values()
|
||||||
.find(|remote| remote.owns_tab(self.active_tab))
|
.find(|remote| remote.owns_tab(self.active_tab))
|
||||||
|
&& let Some(active) = tabs.iter_mut().find(|tab| tab.id == self.active_tab)
|
||||||
{
|
{
|
||||||
|
let panes = remote.visible_panes(active);
|
||||||
return Snapshot {
|
return Snapshot {
|
||||||
revision: self.revision,
|
revision: self.revision,
|
||||||
lineage: self.lineage(),
|
lineage: self.lineage(),
|
||||||
tabs: self.tabs.clone(),
|
tabs,
|
||||||
active_tab: self.active_tab,
|
active_tab: self.active_tab,
|
||||||
panes: remote.visible_panes(self.active_tab),
|
panes,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let visible = self
|
let visible = self
|
||||||
@@ -1269,7 +1272,7 @@ impl SessionState {
|
|||||||
Snapshot {
|
Snapshot {
|
||||||
lineage: self.lineage(),
|
lineage: self.lineage(),
|
||||||
revision: self.revision,
|
revision: self.revision,
|
||||||
tabs: self.tabs.clone(),
|
tabs,
|
||||||
active_tab: self.active_tab,
|
active_tab: self.active_tab,
|
||||||
panes,
|
panes,
|
||||||
}
|
}
|
||||||
|
|||||||
+135
-36
@@ -100,21 +100,31 @@ impl RemoteSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn visible_panes(&self, local: TabId) -> Vec<PaneSnapshot> {
|
pub(super) fn visible_panes(&self, tab: &mut TabInfo) -> Vec<PaneSnapshot> {
|
||||||
self.latest
|
let Some(frame) = self.latest.as_ref() else {
|
||||||
.as_ref()
|
return Vec::new();
|
||||||
.filter(|s| self.tabs.get(&s.active_tab) == Some(&local))
|
};
|
||||||
.map(|s| {
|
let Some(confirmed) = frame
|
||||||
s.panes
|
.active_tab()
|
||||||
.iter()
|
.filter(|remote| self.tabs.get(&remote.id) == Some(&tab.id) && !remote.is_connecting())
|
||||||
.filter_map(|pane| {
|
else {
|
||||||
let mut copy = pane.clone();
|
return Vec::new();
|
||||||
copy.id = *self.panes.get(&pane.id)?;
|
};
|
||||||
Some(copy)
|
// The actor tracks requested focus so consecutive shortcuts can navigate
|
||||||
})
|
// before an SSH round trip. Publish focus and grids from the same frame.
|
||||||
.collect()
|
tab.active_pane = self.panes[&confirmed.active_pane];
|
||||||
|
for (stack, confirmed) in tab.stacks.iter_mut().zip(&confirmed.stacks) {
|
||||||
|
stack.active_pane = self.panes[&confirmed.active_pane];
|
||||||
|
}
|
||||||
|
frame
|
||||||
|
.panes
|
||||||
|
.iter()
|
||||||
|
.map(|pane| {
|
||||||
|
let mut copy = pane.clone();
|
||||||
|
copy.id = self.panes[&pane.id];
|
||||||
|
copy
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reconcile a whole remote session, including other tabs that may already
|
/// Reconcile a whole remote session, including other tabs that may already
|
||||||
@@ -438,21 +448,20 @@ impl SessionState {
|
|||||||
*tab = original(&remote.tabs, *tab)?;
|
*tab = original(&remote.tabs, *tab)?;
|
||||||
Some(remote)
|
Some(remote)
|
||||||
}),
|
}),
|
||||||
NewStackPane { pane, .. } => {
|
// These commands stay within a tab. Let the owner resolve the
|
||||||
let Some(local) = (*pane).or_else(|| {
|
// current pane after all preceding focus requests on its stream.
|
||||||
self.tabs
|
FocusDirection {
|
||||||
.iter()
|
direction: Direction::Up | Direction::Down,
|
||||||
.find(|t| t.id == self.active_tab)
|
|
||||||
.map(|t| t.active_pane)
|
|
||||||
}) else {
|
|
||||||
return Ok(Some(command));
|
|
||||||
};
|
|
||||||
self.remote_pane(local).map(|(remote, original)| {
|
|
||||||
*pane = Some(original);
|
|
||||||
remote
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
Input { pane, .. }
|
| CyclePane { .. }
|
||||||
|
| NewStackPane { pane: None, .. } => self
|
||||||
|
.remotes
|
||||||
|
.values_mut()
|
||||||
|
.find(|remote| original(&remote.tabs, self.active_tab).is_some()),
|
||||||
|
NewStackPane {
|
||||||
|
pane: Some(pane), ..
|
||||||
|
}
|
||||||
|
| Input { pane, .. }
|
||||||
| Resize { pane, .. }
|
| Resize { pane, .. }
|
||||||
| Selection { pane, .. }
|
| Selection { pane, .. }
|
||||||
| Copy { pane }
|
| Copy { pane }
|
||||||
@@ -584,6 +593,103 @@ mod tests {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn receive_updates(updates: crate::client::Updates) -> mpsc::Receiver<Update> {
|
||||||
|
let (frames, receive) = mpsc::channel();
|
||||||
|
thread::spawn(move || {
|
||||||
|
while let Some(update) = updates.recv_blocking() {
|
||||||
|
if frames.send(update).is_err() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
receive
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_frame(
|
||||||
|
receive: &mpsc::Receiver<Update>,
|
||||||
|
accept: impl Fn(&Snapshot) -> bool,
|
||||||
|
) -> Arc<Snapshot> {
|
||||||
|
loop {
|
||||||
|
let update = receive.recv_timeout(Duration::from_secs(5)).unwrap();
|
||||||
|
assert!(update.error.is_none(), "{:?}", update.error);
|
||||||
|
if let Some(frame) = update.snapshot
|
||||||
|
&& accept(&frame)
|
||||||
|
{
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stacked_remote_focus_publishes_matching_grids_while_requests_are_in_flight() {
|
||||||
|
let upstream = super::super::tests::TestServer::start();
|
||||||
|
let (client, updates) =
|
||||||
|
Transport::connect(&upstream.socket, None, SessionTarget::New { cwd: None }).unwrap();
|
||||||
|
let receive = receive_updates(updates);
|
||||||
|
for _ in 0..3 {
|
||||||
|
client
|
||||||
|
.send(ClientMessage::NewStackPane {
|
||||||
|
pane: None,
|
||||||
|
direction: VerticalDirection::Down,
|
||||||
|
cwd: None,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
let initial = next_frame(&receive, |frame| {
|
||||||
|
frame.active_tab().unwrap().panes.len() == 4
|
||||||
|
});
|
||||||
|
let upstream_top = initial.active_tab().unwrap().panes[0];
|
||||||
|
let upstream_third = initial.active_tab().unwrap().panes[2];
|
||||||
|
let mut local = session(1);
|
||||||
|
local.new_tab(None).unwrap();
|
||||||
|
let origin = local.active_tab;
|
||||||
|
let group = reserve(&mut local, 0);
|
||||||
|
local.remotes.get_mut(&group).unwrap().connection = Some(client);
|
||||||
|
apply(&mut local, group, (*initial).clone()).unwrap();
|
||||||
|
let top = local.tabs[1].panes[0];
|
||||||
|
let second = local.tabs[1].panes[1];
|
||||||
|
assert_eq!(local.tabs[1].active_pane, local.tabs[1].panes[3]);
|
||||||
|
|
||||||
|
let output = Arc::new(Outbox::default());
|
||||||
|
let check_frame = |local: &mut SessionState| {
|
||||||
|
let frame = local.snapshot();
|
||||||
|
crate::client::validate_snapshot(&frame).unwrap();
|
||||||
|
let tab = frame.active_tab().unwrap();
|
||||||
|
assert_eq!(frame.panes[0].id, tab.stacks[0].active_pane);
|
||||||
|
assert_eq!(frame.panes[0].id, tab.active_pane);
|
||||||
|
};
|
||||||
|
let up = || ClientMessage::FocusDirection {
|
||||||
|
direction: Direction::Up,
|
||||||
|
};
|
||||||
|
local.command(up(), &output).unwrap();
|
||||||
|
check_frame(&mut local);
|
||||||
|
// Hold the reply to Option+Up while a click selects a different
|
||||||
|
// collapsed pane. Both intermediate snapshots must remain renderable.
|
||||||
|
let third = next_frame(&receive, |frame| {
|
||||||
|
frame.active_tab().unwrap().active_pane == upstream_third
|
||||||
|
});
|
||||||
|
local
|
||||||
|
.command(ClientMessage::FocusPane { pane: second }, &output)
|
||||||
|
.unwrap();
|
||||||
|
check_frame(&mut local);
|
||||||
|
apply(&mut local, group, (*third).clone()).unwrap();
|
||||||
|
// The next Option+Up must move from the clicked pane, even though
|
||||||
|
// the most recent upstream frame still shows the third pane.
|
||||||
|
local.command(up(), &output).unwrap();
|
||||||
|
check_frame(&mut local);
|
||||||
|
local.focus_tab(origin).unwrap();
|
||||||
|
let ack = next_frame(&receive, |frame| {
|
||||||
|
frame.active_tab().unwrap().active_pane == upstream_top
|
||||||
|
});
|
||||||
|
apply(&mut local, group, (*ack).clone()).unwrap();
|
||||||
|
assert_eq!(local.snapshot().active_tab, origin);
|
||||||
|
local.focus_tab(group).unwrap();
|
||||||
|
let frame = local.snapshot();
|
||||||
|
crate::client::validate_snapshot(&frame).unwrap();
|
||||||
|
assert_eq!(frame.active_tab().unwrap().active_pane, top);
|
||||||
|
assert_eq!(frame.panes[0].id, top);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remote_ids_remain_stable_and_do_not_collide_with_local_tabs_or_other_mirrors() {
|
fn remote_ids_remain_stable_and_do_not_collide_with_local_tabs_or_other_mirrors() {
|
||||||
let mut local = session(1);
|
let mut local = session(1);
|
||||||
@@ -649,14 +755,7 @@ mod tests {
|
|||||||
let upstream = super::super::tests::TestServer::start();
|
let upstream = super::super::tests::TestServer::start();
|
||||||
let (client, updates) =
|
let (client, updates) =
|
||||||
Transport::connect(&upstream.socket, None, SessionTarget::New { cwd: None }).unwrap();
|
Transport::connect(&upstream.socket, None, SessionTarget::New { cwd: None }).unwrap();
|
||||||
let (frames, receive) = mpsc::channel();
|
let receive = receive_updates(updates);
|
||||||
thread::spawn(move || {
|
|
||||||
while let Some(update) = updates.recv_blocking() {
|
|
||||||
if frames.send(update).is_err() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let mut local = session(1);
|
let mut local = session(1);
|
||||||
local.new_tab(None).unwrap();
|
local.new_tab(None).unwrap();
|
||||||
let group = reserve(&mut local, 0);
|
let group = reserve(&mut local, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user