Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
Piotr Osiewicz
d8a25dee3b WIP 2023-12-08 16:57:59 +01:00
Kirill Bulatov
0fefe53773 zzz 2023-12-08 13:53:19 +01:00
5 changed files with 377 additions and 222 deletions

View file

@ -214,13 +214,13 @@ impl TerminalPanel {
event: &pane::Event, event: &pane::Event,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
match event { match dbg!(event) {
pane::Event::ActivateItem { .. } => self.serialize(cx), pane::Event::ActivateItem { .. } => self.serialize(cx),
pane::Event::RemoveItem { .. } => self.serialize(cx), pane::Event::RemoveItem { .. } => self.serialize(cx),
pane::Event::Remove => cx.emit(PanelEvent::Close), pane::Event::Remove => cx.emit(PanelEvent::Close),
pane::Event::ZoomIn => cx.emit(PanelEvent::ZoomIn), pane::Event::ZoomIn => cx.emit(PanelEvent::ZoomIn),
pane::Event::ZoomOut => cx.emit(PanelEvent::ZoomOut), pane::Event::ZoomOut => cx.emit(PanelEvent::ZoomOut),
pane::Event::Focus => cx.emit(PanelEvent::Focus), pane::Event::Focus => cx.emit(dbg!(PanelEvent::Focus)),
pane::Event::AddItem { item } => { pane::Event::AddItem { item } => {
if let Some(workspace) = self.workspace.upgrade() { if let Some(workspace) = self.workspace.upgrade() {

View file

@ -1025,11 +1025,13 @@ impl Workspace {
if !panel.has_focus(cx) { if !panel.has_focus(cx) {
cx.focus(&panel); cx.focus(&panel);
} }
dbg!("D");
this.zoomed = Some(panel.downgrade().into_any()); this.zoomed = Some(panel.downgrade().into_any());
this.zoomed_position = Some(panel.read(cx).position(cx)); this.zoomed_position = Some(panel.read(cx).position(cx));
} else if T::should_zoom_out_on_event(event) { } else if T::should_zoom_out_on_event(event) {
dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, false, cx)); dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, false, cx));
if this.zoomed_position == Some(prev_position) { if this.zoomed_position == Some(prev_position) {
dbg!("Losing focus A");
this.zoomed = None; this.zoomed = None;
this.zoomed_position = None; this.zoomed_position = None;
} }
@ -1038,9 +1040,11 @@ impl Workspace {
let position = panel.read(cx).position(cx); let position = panel.read(cx).position(cx);
this.dismiss_zoomed_items_to_reveal(Some(position), cx); this.dismiss_zoomed_items_to_reveal(Some(position), cx);
if panel.is_zoomed(cx) { if panel.is_zoomed(cx) {
dbg!("C");
this.zoomed = Some(panel.downgrade().into_any()); this.zoomed = Some(panel.downgrade().into_any());
this.zoomed_position = Some(position); this.zoomed_position = Some(position);
} else { } else {
dbg!("Losing focus B");
this.zoomed = None; this.zoomed = None;
this.zoomed_position = None; this.zoomed_position = None;
} }
@ -1831,7 +1835,7 @@ impl Workspace {
self.dismiss_zoomed_items_to_reveal(Some(dock_side), cx); self.dismiss_zoomed_items_to_reveal(Some(dock_side), cx);
} }
if focus_center { if dbg!(focus_center) {
cx.focus_self(); cx.focus_self();
} }
@ -1875,6 +1879,7 @@ impl Workspace {
) -> Option<Rc<dyn PanelHandle>> { ) -> Option<Rc<dyn PanelHandle>> {
for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] { for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() { if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
dbg!(panel_index);
let mut focus_center = false; let mut focus_center = false;
let mut reveal_dock = false; let mut reveal_dock = false;
let panel = dock.update(cx, |dock, cx| { let panel = dock.update(cx, |dock, cx| {
@ -1926,6 +1931,7 @@ impl Workspace {
self.left_dock.update(cx, |dock, cx| dock.zoom_out(cx)); self.left_dock.update(cx, |dock, cx| dock.zoom_out(cx));
self.bottom_dock.update(cx, |dock, cx| dock.zoom_out(cx)); self.bottom_dock.update(cx, |dock, cx| dock.zoom_out(cx));
self.right_dock.update(cx, |dock, cx| dock.zoom_out(cx)); self.right_dock.update(cx, |dock, cx| dock.zoom_out(cx));
dbg!("Losing focus C");
self.zoomed = None; self.zoomed = None;
self.zoomed_position = None; self.zoomed_position = None;
@ -1969,6 +1975,7 @@ impl Workspace {
} }
if self.zoomed_position != dock_to_reveal { if self.zoomed_position != dock_to_reveal {
dbg!("losing D");
self.zoomed = None; self.zoomed = None;
self.zoomed_position = None; self.zoomed_position = None;
} }
@ -2313,8 +2320,10 @@ impl Workspace {
self.dismiss_zoomed_items_to_reveal(None, cx); self.dismiss_zoomed_items_to_reveal(None, cx);
if pane.read(cx).is_zoomed() { if pane.read(cx).is_zoomed() {
dbg!("B");
self.zoomed = Some(pane.downgrade().into_any()); self.zoomed = Some(pane.downgrade().into_any());
} else { } else {
dbg!("losing focus E");
self.zoomed = None; self.zoomed = None;
} }
self.zoomed_position = None; self.zoomed_position = None;
@ -2364,6 +2373,7 @@ impl Workspace {
if pane == self.active_pane { if pane == self.active_pane {
pane.update(cx, |pane, cx| pane.set_zoomed(true, cx)); pane.update(cx, |pane, cx| pane.set_zoomed(true, cx));
if pane.read(cx).has_focus() { if pane.read(cx).has_focus() {
dbg!("A");
self.zoomed = Some(pane.downgrade().into_any()); self.zoomed = Some(pane.downgrade().into_any());
self.zoomed_position = None; self.zoomed_position = None;
} }
@ -2373,6 +2383,7 @@ impl Workspace {
pane::Event::ZoomOut => { pane::Event::ZoomOut => {
pane.update(cx, |pane, cx| pane.set_zoomed(false, cx)); pane.update(cx, |pane, cx| pane.set_zoomed(false, cx));
if self.zoomed_position.is_none() { if self.zoomed_position.is_none() {
dbg!("losing focus F");
self.zoomed = None; self.zoomed = None;
} }
cx.notify(); cx.notify();

View file

@ -10,6 +10,7 @@ use std::sync::Arc;
use ui::{h_stack, ContextMenu, IconButton, Tooltip}; use ui::{h_stack, ContextMenu, IconButton, Tooltip};
use ui::{prelude::*, right_click_menu}; use ui::{prelude::*, right_click_menu};
#[derive(Debug)]
pub enum PanelEvent { pub enum PanelEvent {
ChangePosition, ChangePosition,
ZoomIn, ZoomIn,
@ -286,86 +287,143 @@ impl Dock {
workspace: WeakView<Workspace>, workspace: WeakView<Workspace>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
let self_view = cx.view().downgrade();
let subscriptions = [ let subscriptions = [
cx.observe(&panel, |_, _, cx| cx.notify()), cx.observe(&panel, |_, _, cx| cx.notify()),
cx.subscribe(&panel, move |this, panel, event, cx| match event { cx.window_context()
PanelEvent::ChangePosition => { .subscribe(&panel, move |panel, event, cx| match dbg!(event) {
let new_position = panel.read(cx).position(cx); PanelEvent::ChangePosition => {
let new_position = panel.read(cx).position(cx);
let Ok(new_dock) = workspace.update(cx, |workspace, cx| { let Ok(new_dock) = workspace.update(cx, |workspace, cx| {
if panel.is_zoomed(cx) { if panel.is_zoomed(cx) {
workspace.zoomed_position = Some(new_position); workspace.zoomed_position = Some(new_position);
}
match new_position {
DockPosition::Left => &workspace.left_dock,
DockPosition::Bottom => &workspace.bottom_dock,
DockPosition::Right => &workspace.right_dock,
}
.clone()
}) else {
return;
};
let was_visible = this.is_open()
&& this.visible_panel().map_or(false, |active_panel| {
active_panel.entity_id() == Entity::entity_id(&panel)
});
this.remove_panel(&panel, cx);
new_dock.update(cx, |new_dock, cx| {
new_dock.add_panel(panel.clone(), workspace.clone(), cx);
if was_visible {
new_dock.set_open(true, cx);
new_dock.activate_panel(this.panels_len() - 1, cx);
}
});
}
PanelEvent::ZoomIn => {
this.set_panel_zoomed(&panel.to_any(), true, cx);
if !panel.focus_handle(cx).contains_focused(cx) {
cx.focus_view(&panel);
}
workspace
.update(cx, |workspace, cx| {
workspace.zoomed = Some(panel.downgrade().into());
workspace.zoomed_position = Some(panel.read(cx).position(cx));
})
.ok();
}
PanelEvent::ZoomOut => {
this.set_panel_zoomed(&panel.to_any(), false, cx);
workspace
.update(cx, |workspace, cx| {
if workspace.zoomed_position == Some(this.position) {
workspace.zoomed = None;
workspace.zoomed_position = None;
} }
cx.notify(); match new_position {
}) DockPosition::Left => &workspace.left_dock,
.ok(); DockPosition::Bottom => &workspace.bottom_dock,
} DockPosition::Right => &workspace.right_dock,
PanelEvent::Activate => { }
if let Some(ix) = this .clone()
.panel_entries }) else {
.iter() return;
.position(|entry| entry.panel.entity_id() == Entity::entity_id(&panel)) };
{
this.set_open(true, cx); let Ok(was_visible) = self_view.update(cx, |this, cx| {
this.activate_panel(ix, cx); this.is_open()
cx.focus_view(&panel); && this.visible_panel().map_or(false, |active_panel| {
active_panel.entity_id() == Entity::entity_id(&panel)
})
}) else {
return;
};
self_view.update(cx, |this, cx| this.remove_panel(&panel, cx));
new_dock.update(cx, |new_dock, cx| {
new_dock.add_panel(panel.clone(), workspace.clone(), cx);
if was_visible {
new_dock.set_open(true, cx);
self_view.update(cx, |this, cx| {
new_dock.activate_panel(this.panels_len() - 1, cx)
});
}
});
} }
} PanelEvent::ZoomIn => {
PanelEvent::Close => { self_view.update(cx, |this, cx| {
if this this.set_panel_zoomed(&panel.to_any(), true, cx)
.visible_panel() });
.map_or(false, |p| p.entity_id() == Entity::entity_id(&panel)) if !panel.focus_handle(cx).contains_focused(cx) {
{ cx.focus_view(&panel);
this.set_open(false, cx); }
workspace
.update(cx, |workspace, cx| {
workspace.zoomed = Some(panel.downgrade().into());
workspace.zoomed_position = Some(panel.read(cx).position(cx));
})
.ok();
} }
} PanelEvent::ZoomOut => {
PanelEvent::Focus => todo!(), self_view.update(cx, |this, cx| {
}), this.set_panel_zoomed(&panel.to_any(), false, cx)
});
workspace
.update(cx, |workspace, cx| {
if workspace.zoomed_position
== Some(self_view.update(cx, |this, cx| this.position).ok())
.flatten()
{
dbg!("Losing focus A");
workspace.zoomed = None;
workspace.zoomed_position = None;
}
cx.notify();
})
.ok();
}
PanelEvent::Activate => {
if self_view
.update(cx, |this, cx| {
if let Some(ix) = this.panel_entries.iter().position(|entry| {
entry.panel.entity_id() == Entity::entity_id(&panel)
}) {
this.set_open(true, cx);
this.activate_panel(ix, cx);
return true;
}
false
})
.ok()
.unwrap_or(false)
{
cx.focus_view(&panel);
}
}
PanelEvent::Close => {
self_view
.update(cx, |this, cx| {
if this
.visible_panel()
.map_or(false, |p| p.entity_id() == Entity::entity_id(&panel))
{
this.set_open(false, cx);
}
})
.ok();
}
PanelEvent::Focus => {
let position = panel.read(cx).position(cx);
workspace
.update(cx, |this, cx| {
this.dismiss_zoomed_items_to_reveal(Some(position), cx)
})
.ok();
if panel.is_zoomed(cx) {
dbg!("C");
workspace
.update(cx, |this, cx| {
this.zoomed = Some(panel.downgrade().into());
this.zoomed_position = Some(position);
})
.ok();
} else {
workspace
.update(cx, |this, cx| {
dbg!("Losing focus B");
this.zoomed = None;
this.zoomed_position = None;
})
.ok();
}
workspace
.update(cx, |this, cx| {
this.update_active_view_for_followers(cx);
})
.ok();
cx.notify();
}
}),
]; ];
// todo!() // todo!()
@ -775,12 +833,18 @@ pub mod test {
impl EventEmitter<PanelEvent> for TestPanel {} impl EventEmitter<PanelEvent> for TestPanel {}
impl TestPanel { impl TestPanel {
pub fn new(position: DockPosition, cx: &mut WindowContext) -> Self { pub fn new(position: DockPosition, cx: &mut ViewContext<Self>) -> Self {
cx.emit(PanelEvent::Focus);
let focus_handle = cx.focus_handle();
cx.on_focus_in(&focus_handle, move |_, cx| {
cx.emit(PanelEvent::Focus);
})
.detach();
Self { Self {
position, position,
zoomed: false, zoomed: false,
active: false, active: false,
focus_handle: cx.focus_handle(), focus_handle,
size: 300., size: 300.,
} }
} }
@ -832,12 +896,24 @@ pub mod test {
self.zoomed self.zoomed
} }
fn set_zoomed(&mut self, zoomed: bool, _cx: &mut ViewContext<Self>) { fn set_zoomed(&mut self, zoomed: bool, cx: &mut ViewContext<Self>) {
self.zoomed = zoomed; self.zoomed = zoomed;
let event = if zoomed {
PanelEvent::ZoomIn
} else {
PanelEvent::ZoomOut
};
cx.emit(event)
} }
fn set_active(&mut self, active: bool, _cx: &mut ViewContext<Self>) { fn set_active(&mut self, active: bool, cx: &mut ViewContext<Self>) {
self.active = active; self.active = dbg!(active);
// let event = if active {
// PanelEvent::Activate
// } else {
// PanelEvent::Close
// };
// cx.emit(event)
} }
} }

View file

@ -1493,7 +1493,7 @@ impl Pane {
.child(label); .child(label);
right_click_menu(ix).trigger(tab).menu(|cx| { right_click_menu(ix).trigger(tab).menu(|cx| {
ContextMenu::build(cx, |menu, cx| { ContextMenu::build(cx, |menu, _| {
menu.action("Close", CloseActiveItem { save_intent: None }.boxed_clone()) menu.action("Close", CloseActiveItem { save_intent: None }.boxed_clone())
.action("Close Others", CloseInactiveItems.boxed_clone()) .action("Close Others", CloseInactiveItems.boxed_clone())
.separator() .separator()
@ -2057,13 +2057,13 @@ impl Render for Pane {
.overflow_hidden() .overflow_hidden()
.on_focus_in({ .on_focus_in({
let this = this.clone(); let this = this.clone();
move |event, cx| { move |_, cx| {
this.update(cx, |this, cx| this.focus_in(cx)).ok(); this.update(cx, |this, cx| this.focus_in(cx)).ok();
} }
}) })
.on_focus_out({ .on_focus_out({
let this = this.clone(); let this = this.clone();
move |event, cx| { move |_, cx| {
this.update(cx, |this, cx| this.focus_out(cx)).ok(); this.update(cx, |this, cx| this.focus_out(cx)).ok();
} }
}) })

View file

@ -1542,13 +1542,16 @@ impl Workspace {
dock.set_open(!was_visible, cx); dock.set_open(!was_visible, cx);
if let Some(active_panel) = dock.active_panel() { if let Some(active_panel) = dock.active_panel() {
dbg!(dock_side);
if was_visible { if was_visible {
if active_panel.focus_handle(cx).contains_focused(cx) { if active_panel.focus_handle(cx).contains_focused(cx) {
focus_center = true; focus_center = true;
} }
} else { } else {
let focus_handle = &active_panel.focus_handle(cx); let focus_handle = &active_panel.focus_handle(cx);
dbg!(&focus_handle);
cx.focus(focus_handle); cx.focus(focus_handle);
assert!(focus_handle.is_focused(cx));
reveal_dock = true; reveal_dock = true;
} }
} }
@ -1558,6 +1561,7 @@ impl Workspace {
self.dismiss_zoomed_items_to_reveal(Some(dock_side), cx); self.dismiss_zoomed_items_to_reveal(Some(dock_side), cx);
} }
dbg!(focus_center);
if focus_center { if focus_center {
self.active_pane.update(cx, |pane, cx| pane.focus(cx)) self.active_pane.update(cx, |pane, cx| pane.focus(cx))
} }
@ -1603,6 +1607,7 @@ impl Workspace {
) -> Option<Arc<dyn PanelHandle>> { ) -> Option<Arc<dyn PanelHandle>> {
for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] { for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() { if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
dbg!(panel_index);
let mut focus_center = false; let mut focus_center = false;
let mut reveal_dock = false; let mut reveal_dock = false;
let panel = dock.update(cx, |dock, cx| { let panel = dock.update(cx, |dock, cx| {
@ -1615,9 +1620,9 @@ impl Workspace {
panel.focus_handle(cx).focus(cx); panel.focus_handle(cx).focus(cx);
reveal_dock = true; reveal_dock = true;
} else { } else {
// if panel.is_zoomed(cx) { if panel.is_zoomed(cx) {
// dock.set_open(false, cx); dock.set_open(false, cx);
// } }
focus_center = true; focus_center = true;
} }
} }
@ -1654,6 +1659,7 @@ impl Workspace {
self.left_dock.update(cx, |dock, cx| dock.zoom_out(cx)); self.left_dock.update(cx, |dock, cx| dock.zoom_out(cx));
self.bottom_dock.update(cx, |dock, cx| dock.zoom_out(cx)); self.bottom_dock.update(cx, |dock, cx| dock.zoom_out(cx));
self.right_dock.update(cx, |dock, cx| dock.zoom_out(cx)); self.right_dock.update(cx, |dock, cx| dock.zoom_out(cx));
dbg!("Losing focus C");
self.zoomed = None; self.zoomed = None;
self.zoomed_position = None; self.zoomed_position = None;
@ -1697,6 +1703,7 @@ impl Workspace {
} }
if self.zoomed_position != dock_to_reveal { if self.zoomed_position != dock_to_reveal {
dbg!("losing D");
self.zoomed = None; self.zoomed = None;
self.zoomed_position = None; self.zoomed_position = None;
} }
@ -1738,8 +1745,10 @@ impl Workspace {
} }
pub fn add_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) { pub fn add_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) {
self.active_pane self.active_pane.update(cx, |pane, cx| {
.update(cx, |pane, cx| pane.add_item(item, true, true, None, cx)); dbg!(pane.items_len());
pane.add_item(item, true, true, None, cx)
});
} }
pub fn split_item( pub fn split_item(
@ -2050,8 +2059,10 @@ impl Workspace {
self.dismiss_zoomed_items_to_reveal(None, cx); self.dismiss_zoomed_items_to_reveal(None, cx);
if pane.read(cx).is_zoomed() { if pane.read(cx).is_zoomed() {
dbg!("B");
self.zoomed = Some(pane.downgrade().into()); self.zoomed = Some(pane.downgrade().into());
} else { } else {
dbg!("losing focus E");
self.zoomed = None; self.zoomed = None;
} }
self.zoomed_position = None; self.zoomed_position = None;
@ -2102,6 +2113,7 @@ impl Workspace {
if pane == self.active_pane { if pane == self.active_pane {
pane.update(cx, |pane, cx| pane.set_zoomed(true, cx)); pane.update(cx, |pane, cx| pane.set_zoomed(true, cx));
if pane.read(cx).has_focus(cx) { if pane.read(cx).has_focus(cx) {
dbg!("A");
self.zoomed = Some(pane.downgrade().into()); self.zoomed = Some(pane.downgrade().into());
self.zoomed_position = None; self.zoomed_position = None;
} }
@ -2111,6 +2123,7 @@ impl Workspace {
pane::Event::ZoomOut => { pane::Event::ZoomOut => {
pane.update(cx, |pane, cx| pane.set_zoomed(false, cx)); pane.update(cx, |pane, cx| pane.set_zoomed(false, cx));
if self.zoomed_position.is_none() { if self.zoomed_position.is_none() {
dbg!("losing focus F");
self.zoomed = None; self.zoomed = None;
} }
cx.notify(); cx.notify();
@ -2233,6 +2246,7 @@ impl Workspace {
} }
fn remove_pane(&mut self, pane: View<Pane>, cx: &mut ViewContext<Self>) { fn remove_pane(&mut self, pane: View<Pane>, cx: &mut ViewContext<Self>) {
dbg!("?????@@@@@@@@@@ remove pane");
if self.center.remove(&pane).unwrap() { if self.center.remove(&pane).unwrap() {
self.force_remove_pane(&pane, cx); self.force_remove_pane(&pane, cx);
self.unfollow(&pane, cx); self.unfollow(&pane, cx);
@ -2241,8 +2255,14 @@ impl Workspace {
self.panes_by_item.remove(&removed_item.item_id()); self.panes_by_item.remove(&removed_item.item_id());
} }
dbg!("######### removed the pane", self.panes.len());
// cx.focus_self();
cx.notify(); cx.notify();
} else { } else {
dbg!(
"??????????? during pane removal, we decided to spare the pane and not removed it (main pane)"
);
self.active_item_path_changed(cx); self.active_item_path_changed(cx);
} }
} }
@ -4400,9 +4420,12 @@ fn parse_pixel_size_env_var(value: &str) -> Option<Size<GlobalPixels>> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::item::{ use crate::{
test::{TestItem, TestProjectItem}, dock::test::TestPanel,
ItemEvent, item::{
test::{TestItem, TestProjectItem},
ItemEvent,
},
}; };
use fs::FakeFs; use fs::FakeFs;
use gpui::TestAppContext; use gpui::TestAppContext;
@ -4975,153 +4998,198 @@ mod tests {
}); });
} }
// #[gpui::test] #[gpui::test]
// async fn test_toggle_docks_and_panels(cx: &mut gpui::TestAppContext) { async fn test_toggle_docks_and_panels(cx: &mut gpui::TestAppContext) {
// init_test(cx); init_test(cx);
// let fs = FakeFs::new(cx.executor()); let fs = FakeFs::new(cx.background_executor.clone());
// let project = Project::test(fs, [], cx).await; let project = Project::test(fs, [], cx).await;
// let window = cx.add_window(|cx| Workspace::test_new(project, cx)); let window = cx.add_window(|cx| Workspace::test_new(project, cx));
// let workspace = window.root(cx); let workspace = window.root(cx).unwrap();
// let panel = workspace.update(cx, |workspace, cx| { let panel = window
// let panel = cx.build_view(|_| TestPanel::new(DockPosition::Right)); .update(cx, |workspace, cx| {
// workspace.add_panel(panel.clone(), cx); let (panel, right_dock) = {
let panel = cx.build_view(|cx| TestPanel::new(DockPosition::Right, cx));
workspace.add_panel(panel.clone(), cx);
// workspace (panel, workspace.right_dock().clone())
// .right_dock() };
// .update(cx, |right_dock, cx| right_dock.set_open(true, cx)); dbg!("A");
right_dock.update(cx, |this, cx| this.set_open(true, cx));
dbg!("B");
panel
})
.unwrap();
dbg!("C");
let pane = cx
.update_window(window.into(), |_, cx| {
workspace.update(cx, |workspace, _| workspace.active_pane().clone())
})
.unwrap();
cx.update_window(window.into(), |_, cx| {
pane.update(cx, |pane, cx| {
let item = cx.build_view(|cx| TestItem::new(cx));
pane.add_item(Box::new(item), true, true, None, cx);
})
})
.unwrap();
// Transfer focus from center to panel
cx.update_window(window.into(), |_, cx| {
workspace.update(cx, |workspace, cx| {
workspace.toggle_panel_focus::<TestPanel>(cx);
});
})
.unwrap();
cx.update_window(window.into(), |_, cx| {
workspace.update(cx, |workspace, cx| {
assert!(workspace.right_dock().read(cx).is_open());
// assert!(!panel.is_zoomed(cx));
assert!(panel.focus_handle(cx).is_focused(cx));
});
})
.unwrap();
// panel // Transfer focus from panel to center
// }); cx.update_window(window.into(), |_, cx| {
workspace.update(cx, |workspace, cx| {
workspace.toggle_panel_focus::<TestPanel>(cx);
})
});
cx.update_window(window.into(), |_, cx| {
workspace.update(cx, |workspace, cx| {
assert!(workspace.right_dock().read(cx).is_open());
// assert!(!panel.is_zoomed(cx));
assert!(!panel.focus_handle(cx).is_focused(cx));
})
});
// let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone()); // Close the dock
// pane.update(cx, |pane, cx| { cx.update_window(window.into(), |_, cx| {
// let item = cx.build_view(|_| TestItem::new(cx)); workspace.update(cx, |workspace, cx| {
// pane.add_item(Box::new(item), true, true, None, cx); workspace.toggle_dock(DockPosition::Right, cx);
// }); })
});
cx.update_window(window.into(), |_, cx| {
workspace.update(cx, |workspace, cx| {
assert!(!workspace.right_dock().read(cx).is_open());
// assert!(!panel.is_zoomed(cx));
assert!(!panel.focus_handle(cx).is_focused(cx));
})
});
// // Transfer focus from center to panel // Open the dock
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// workspace.toggle_panel_focus::<TestPanel>(cx); workspace.update(cx, |workspace, cx| {
// }); workspace.toggle_dock(DockPosition::Right, cx);
})
});
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// assert!(workspace.right_dock().read(cx).is_open()); workspace.update(cx, |workspace, cx| {
// assert!(!panel.is_zoomed(cx)); assert!(workspace.right_dock().read(cx).is_open());
// assert!(panel.has_focus(cx)); // assert!(!panel.is_zoomed(cx));
// }); assert!(panel.focus_handle(cx).is_focused(cx));
})
});
// // Transfer focus from panel to center // Focus and zoom panel
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// workspace.toggle_panel_focus::<TestPanel>(cx); panel.update(cx, |panel, cx| {
// }); cx.focus_self();
panel.set_zoomed(true, cx)
})
});
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// assert!(workspace.right_dock().read(cx).is_open()); workspace.update(cx, |workspace, cx| {
// assert!(!panel.is_zoomed(cx)); assert!(workspace.right_dock().read(cx).is_open());
// assert!(!panel.has_focus(cx)); assert!(panel.is_zoomed(cx));
// }); assert!(panel.focus_handle(cx).is_focused(cx));
})
});
// // Close the dock // Transfer focus to the center closes the dock
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// workspace.toggle_dock(DockPosition::Right, cx); workspace.update(cx, |workspace, cx| {
// }); workspace.toggle_panel_focus::<TestPanel>(cx);
})
});
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// assert!(!workspace.right_dock().read(cx).is_open()); workspace.update(cx, |workspace, cx| {
// assert!(!panel.is_zoomed(cx)); assert!(!workspace.right_dock().read(cx).is_open());
// assert!(!panel.has_focus(cx)); assert!(panel.is_zoomed(cx));
// }); assert!(!panel.focus_handle(cx).is_focused(cx));
})
});
// // Open the dock // Transferring focus back to the panel keeps it zoomed
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// workspace.toggle_dock(DockPosition::Right, cx); workspace.update(cx, |workspace, cx| {
// }); workspace.toggle_panel_focus::<TestPanel>(cx);
});
});
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// assert!(workspace.right_dock().read(cx).is_open()); workspace.update(cx, |workspace, cx| {
// assert!(!panel.is_zoomed(cx)); assert!(workspace.right_dock().read(cx).is_open());
// assert!(panel.has_focus(cx)); assert!(panel.is_zoomed(cx));
// }); assert!(panel.focus_handle(cx).is_focused(cx));
})
});
// // Focus and zoom panel // Close the dock while it is zoomed
// panel.update(cx, |panel, cx| { cx.update_window(window.into(), |_, cx| {
// cx.focus_self(); workspace.update(cx, |workspace, cx| {
// panel.set_zoomed(true, cx) workspace.toggle_dock(DockPosition::Right, cx)
// }); })
});
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// assert!(workspace.right_dock().read(cx).is_open()); workspace.update(cx, |workspace, cx| {
// assert!(panel.is_zoomed(cx)); assert!(!workspace.right_dock().read(cx).is_open());
// assert!(panel.has_focus(cx)); assert!(panel.is_zoomed(cx));
// }); assert!(workspace.zoomed.is_none());
assert!(!panel.focus_handle(cx).is_focused(cx));
})
});
// // Transfer focus to the center closes the dock // Opening the dock, when it's zoomed, retains focus
// workspace.update(cx, |workspace, cx| { cx.update_window(window.into(), |_, cx| {
// workspace.toggle_panel_focus::<TestPanel>(cx); workspace.update(cx, |workspace, cx| {
// }); workspace.toggle_dock(DockPosition::Right, cx)
})
});
cx.executor().run_until_parked();
cx.update_window(window.into(), |_, cx| {
workspace.update(cx, |workspace, cx| {
assert!(workspace.right_dock().read(cx).is_open());
assert!(panel.is_zoomed(cx));
assert!(workspace.zoomed.is_some());
assert!(panel.focus_handle(cx).is_focused(cx));
})
});
// workspace.update(cx, |workspace, cx| { // // Unzoom and close the panel, zoom the active pane.
// assert!(!workspace.right_dock().read(cx).is_open()); // panel.update(cx, |panel, cx| panel.set_zoomed(false, cx));
// assert!(panel.is_zoomed(cx)); // workspace.update(cx, |workspace, cx| {
// assert!(!panel.has_focus(cx)); // workspace.toggle_dock(DockPosition::Right, cx)
// }); // });
// pane.update(cx, |pane, cx| pane.toggle_zoom(&Default::default(), cx));
// // Transferring focus back to the panel keeps it zoomed // // Opening a dock unzooms the pane.
// workspace.update(cx, |workspace, cx| { // workspace.update(cx, |workspace, cx| {
// workspace.toggle_panel_focus::<TestPanel>(cx); // workspace.toggle_dock(DockPosition::Right, cx)
// }); // });
// workspace.update(cx, |workspace, cx| {
// workspace.update(cx, |workspace, cx| { // let pane = pane.read(cx);
// assert!(workspace.right_dock().read(cx).is_open()); // // assert!(!pane.is_zoomed());
// assert!(panel.is_zoomed(cx)); // assert!(!pane.focus_handle(cx).is_focused(cx));
// assert!(panel.has_focus(cx)); // assert!(workspace.right_dock().read(cx).is_open());
// }); // assert!(workspace.zoomed.is_none());
// });
// // Close the dock while it is zoomed }
// workspace.update(cx, |workspace, cx| {
// workspace.toggle_dock(DockPosition::Right, cx)
// });
// workspace.update(cx, |workspace, cx| {
// assert!(!workspace.right_dock().read(cx).is_open());
// assert!(panel.is_zoomed(cx));
// assert!(workspace.zoomed.is_none());
// assert!(!panel.has_focus(cx));
// });
// // Opening the dock, when it's zoomed, retains focus
// workspace.update(cx, |workspace, cx| {
// workspace.toggle_dock(DockPosition::Right, cx)
// });
// workspace.update(cx, |workspace, cx| {
// assert!(workspace.right_dock().read(cx).is_open());
// assert!(panel.is_zoomed(cx));
// assert!(workspace.zoomed.is_some());
// assert!(panel.has_focus(cx));
// });
// // Unzoom and close the panel, zoom the active pane.
// panel.update(cx, |panel, cx| panel.set_zoomed(false, cx));
// workspace.update(cx, |workspace, cx| {
// workspace.toggle_dock(DockPosition::Right, cx)
// });
// pane.update(cx, |pane, cx| pane.toggle_zoom(&Default::default(), cx));
// // Opening a dock unzooms the pane.
// workspace.update(cx, |workspace, cx| {
// workspace.toggle_dock(DockPosition::Right, cx)
// });
// workspace.update(cx, |workspace, cx| {
// let pane = pane.read(cx);
// assert!(!pane.is_zoomed());
// assert!(!pane.has_focus());
// assert!(workspace.right_dock().read(cx).is_open());
// assert!(workspace.zoomed.is_none());
// });
// }
// #[gpui::test] // #[gpui::test]
// async fn test_panels(cx: &mut gpui::TestAppContext) { // async fn test_panels(cx: &mut gpui::TestAppContext) {