Cycle through panes spatially rather than in the order in which they created
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
5ac39aa7cd
commit
60b6b0b317
2 changed files with 36 additions and 17 deletions
|
@ -57,6 +57,12 @@ impl PaneGroup {
|
|||
) -> ElementBox {
|
||||
self.root.render(theme, follower_states, collaborators)
|
||||
}
|
||||
|
||||
pub(crate) fn panes(&self) -> Vec<&ViewHandle<Pane>> {
|
||||
let mut panes = Vec::new();
|
||||
self.root.collect_panes(&mut panes);
|
||||
panes
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
|
@ -122,6 +128,17 @@ impl Member {
|
|||
Member::Axis(axis) => axis.render(theme, follower_states, collaborators),
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_panes<'a>(&'a self, panes: &mut Vec<&'a ViewHandle<Pane>>) {
|
||||
match self {
|
||||
Member::Axis(axis) => {
|
||||
for member in &axis.members {
|
||||
member.collect_panes(panes);
|
||||
}
|
||||
}
|
||||
Member::Pane(pane) => panes.push(pane),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
|
|
|
@ -1160,27 +1160,29 @@ impl Workspace {
|
|||
}
|
||||
|
||||
pub fn activate_next_pane(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let ix = self
|
||||
.panes
|
||||
let next_pane = {
|
||||
let panes = self.center.panes();
|
||||
let ix = panes
|
||||
.iter()
|
||||
.position(|pane| pane == &self.active_pane)
|
||||
.position(|pane| **pane == self.active_pane)
|
||||
.unwrap();
|
||||
let next_ix = (ix + 1) % self.panes.len();
|
||||
self.activate_pane(self.panes[next_ix].clone(), cx);
|
||||
let next_ix = (ix + 1) % panes.len();
|
||||
panes[next_ix].clone()
|
||||
};
|
||||
self.activate_pane(next_pane, cx);
|
||||
}
|
||||
|
||||
pub fn activate_previous_pane(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let ix = self
|
||||
.panes
|
||||
let prev_pane = {
|
||||
let panes = self.center.panes();
|
||||
let ix = panes
|
||||
.iter()
|
||||
.position(|pane| pane == &self.active_pane)
|
||||
.position(|pane| **pane == self.active_pane)
|
||||
.unwrap();
|
||||
let prev_ix = if ix == 0 {
|
||||
self.panes.len() - 1
|
||||
} else {
|
||||
ix - 1
|
||||
let prev_ix = if ix == 0 { panes.len() - 1 } else { ix - 1 };
|
||||
panes[prev_ix].clone()
|
||||
};
|
||||
self.activate_pane(self.panes[prev_ix].clone(), cx);
|
||||
self.activate_pane(prev_pane, cx);
|
||||
}
|
||||
|
||||
fn activate_pane(&mut self, pane: ViewHandle<Pane>, cx: &mut ViewContext<Self>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue