Maintain workspace's zoom state when opening/closing docks, activating panels (#3801)
Fixes an issue where zoom didn't work when closing and re-opening a zoomed panel.
This commit is contained in:
commit
2edf560e5c
2 changed files with 37 additions and 21 deletions
|
@ -192,21 +192,43 @@ pub struct PanelButtons {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dock {
|
impl Dock {
|
||||||
pub fn new(position: DockPosition, cx: &mut ViewContext<'_, Self>) -> Self {
|
pub fn new(position: DockPosition, cx: &mut ViewContext<Workspace>) -> View<Self> {
|
||||||
let focus_handle = cx.focus_handle();
|
let focus_handle = cx.focus_handle();
|
||||||
let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| {
|
|
||||||
if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) {
|
let dock = cx.build_view(|cx: &mut ViewContext<Self>| {
|
||||||
active_entry.panel.focus_handle(cx).focus(cx)
|
let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| {
|
||||||
|
if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) {
|
||||||
|
active_entry.panel.focus_handle(cx).focus(cx)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Self {
|
||||||
|
position,
|
||||||
|
panel_entries: Default::default(),
|
||||||
|
active_panel_index: 0,
|
||||||
|
is_open: false,
|
||||||
|
focus_handle: focus_handle.clone(),
|
||||||
|
_focus_subscription: focus_subscription,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Self {
|
|
||||||
position,
|
cx.observe(&dock, move |workspace, dock, cx| {
|
||||||
panel_entries: Default::default(),
|
if dock.read(cx).is_open() {
|
||||||
active_panel_index: 0,
|
if let Some(panel) = dock.read(cx).active_panel() {
|
||||||
is_open: false,
|
if panel.is_zoomed(cx) {
|
||||||
focus_handle,
|
workspace.zoomed = Some(panel.to_any().downgrade());
|
||||||
_focus_subscription: focus_subscription,
|
workspace.zoomed_position = Some(position);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if workspace.zoomed_position == Some(position) {
|
||||||
|
workspace.zoomed = None;
|
||||||
|
workspace.zoomed_position = None;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
dock
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(&self) -> DockPosition {
|
pub fn position(&self) -> DockPosition {
|
||||||
|
|
|
@ -586,9 +586,9 @@ impl Workspace {
|
||||||
|
|
||||||
cx.emit(Event::WorkspaceCreated(weak_handle.clone()));
|
cx.emit(Event::WorkspaceCreated(weak_handle.clone()));
|
||||||
|
|
||||||
let left_dock = cx.build_view(|cx| Dock::new(DockPosition::Left, cx));
|
let left_dock = Dock::new(DockPosition::Left, cx);
|
||||||
let bottom_dock = cx.build_view(|cx| Dock::new(DockPosition::Bottom, cx));
|
let bottom_dock = Dock::new(DockPosition::Bottom, cx);
|
||||||
let right_dock = cx.build_view(|cx| Dock::new(DockPosition::Right, cx));
|
let right_dock = Dock::new(DockPosition::Right, cx);
|
||||||
let left_dock_buttons = cx.build_view(|cx| PanelButtons::new(left_dock.clone(), cx));
|
let left_dock_buttons = cx.build_view(|cx| PanelButtons::new(left_dock.clone(), cx));
|
||||||
let bottom_dock_buttons = cx.build_view(|cx| PanelButtons::new(bottom_dock.clone(), cx));
|
let bottom_dock_buttons = cx.build_view(|cx| PanelButtons::new(bottom_dock.clone(), cx));
|
||||||
let right_dock_buttons = cx.build_view(|cx| PanelButtons::new(right_dock.clone(), cx));
|
let right_dock_buttons = cx.build_view(|cx| PanelButtons::new(right_dock.clone(), cx));
|
||||||
|
@ -1616,7 +1616,6 @@ impl Workspace {
|
||||||
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>() {
|
||||||
let mut focus_center = false;
|
let mut focus_center = false;
|
||||||
let mut reveal_dock = false;
|
|
||||||
let panel = dock.update(cx, |dock, cx| {
|
let panel = dock.update(cx, |dock, cx| {
|
||||||
dock.activate_panel(panel_index, cx);
|
dock.activate_panel(panel_index, cx);
|
||||||
|
|
||||||
|
@ -1625,12 +1624,7 @@ impl Workspace {
|
||||||
if should_focus(&**panel, cx) {
|
if should_focus(&**panel, cx) {
|
||||||
dock.set_open(true, cx);
|
dock.set_open(true, cx);
|
||||||
panel.focus_handle(cx).focus(cx);
|
panel.focus_handle(cx).focus(cx);
|
||||||
reveal_dock = true;
|
|
||||||
} else {
|
} else {
|
||||||
// todo!()
|
|
||||||
// if panel.is_zoomed(cx) {
|
|
||||||
// dock.set_open(false, cx);
|
|
||||||
// }
|
|
||||||
focus_center = true;
|
focus_center = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue