Merge pull request #2019 from zed-industries/panic-activating-next-pane-in-dock
Fix crash when activating prev/next pane while dock is active
This commit is contained in:
commit
ef987cae6b
2 changed files with 26 additions and 19 deletions
|
@ -623,6 +623,20 @@ mod tests {
|
||||||
cx.assert_dock_pane_active();
|
cx.assert_dock_pane_active();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_activate_next_and_prev_pane(cx: &mut TestAppContext) {
|
||||||
|
let mut cx = DockTestContext::new(cx).await;
|
||||||
|
|
||||||
|
cx.move_dock(DockAnchor::Right);
|
||||||
|
cx.assert_dock_pane_active();
|
||||||
|
|
||||||
|
cx.update_workspace(|workspace, cx| workspace.activate_next_pane(cx));
|
||||||
|
cx.assert_dock_pane_active();
|
||||||
|
|
||||||
|
cx.update_workspace(|workspace, cx| workspace.activate_previous_pane(cx));
|
||||||
|
cx.assert_dock_pane_active();
|
||||||
|
}
|
||||||
|
|
||||||
struct DockTestContext<'a> {
|
struct DockTestContext<'a> {
|
||||||
pub cx: &'a mut TestAppContext,
|
pub cx: &'a mut TestAppContext,
|
||||||
pub window_id: usize,
|
pub window_id: usize,
|
||||||
|
|
|
@ -44,6 +44,7 @@ use language::LanguageRegistry;
|
||||||
use std::{
|
use std::{
|
||||||
any::TypeId,
|
any::TypeId,
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
|
cmp,
|
||||||
future::Future,
|
future::Future,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
@ -1415,29 +1416,21 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn activate_next_pane(&mut self, cx: &mut ViewContext<Self>) {
|
pub fn activate_next_pane(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
let next_pane = {
|
let panes = self.center.panes();
|
||||||
let panes = self.center.panes();
|
if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) {
|
||||||
let ix = panes
|
|
||||||
.iter()
|
|
||||||
.position(|pane| **pane == self.active_pane)
|
|
||||||
.unwrap();
|
|
||||||
let next_ix = (ix + 1) % panes.len();
|
let next_ix = (ix + 1) % panes.len();
|
||||||
panes[next_ix].clone()
|
let next_pane = panes[next_ix].clone();
|
||||||
};
|
cx.focus(next_pane);
|
||||||
cx.focus(next_pane);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn activate_previous_pane(&mut self, cx: &mut ViewContext<Self>) {
|
pub fn activate_previous_pane(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
let prev_pane = {
|
let panes = self.center.panes();
|
||||||
let panes = self.center.panes();
|
if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) {
|
||||||
let ix = panes
|
let prev_ix = cmp::min(ix.wrapping_sub(1), panes.len() - 1);
|
||||||
.iter()
|
let prev_pane = panes[prev_ix].clone();
|
||||||
.position(|pane| **pane == self.active_pane)
|
cx.focus(prev_pane);
|
||||||
.unwrap();
|
}
|
||||||
let prev_ix = if ix == 0 { panes.len() - 1 } else { ix - 1 };
|
|
||||||
panes[prev_ix].clone()
|
|
||||||
};
|
|
||||||
cx.focus(prev_pane);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_pane_focused(&mut self, pane: ViewHandle<Pane>, cx: &mut ViewContext<Self>) {
|
fn handle_pane_focused(&mut self, pane: ViewHandle<Pane>, cx: &mut ViewContext<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue