Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix active pane border and pane opacity dimming showing simultaneously on editor panes and terminal panes (#56595)

Aks8f6f8a54b993
diff --git a/crates/workspace/src/pane_group.rs b/crates/workspace/src/pane_group.rs
index 3b0d07dcf25..672190aff60 100644
--- a/crates/workspace/src/pane_group.rs
+++ b/crates/workspace/src/pane_group.rs
@@ -35,6 +35,8 @@ pub struct PaneGroup {
pub struct PaneRenderResult {
pub element: gpui::AnyElement,
pub contains_active_pane: bool,
+ #[cfg(any(test, feature = "test-support"))]
+ pub decorated_pane_ix: Option<usize>,
}
impl PaneGroup {
@@ -542,6 +544,8 @@ impl Member {
return PaneRenderResult {
element: div().into_any(),
contains_active_pane: false,
+ #[cfg(any(test, feature = "test-support"))]
+ decorated_pane_ix: None,
};
}
@@ -550,6 +554,8 @@ impl Member {
return PaneRenderResult {
element: div().into_any(),
contains_active_pane: false,
+ #[cfg(any(test, feature = "test-support"))]
+ decorated_pane_ix: None,
};
}
true
@@ -596,6 +602,8 @@ impl Member {
.child(pane)
.into_any(),
contains_active_pane: is_active,
+ #[cfg(any(test, feature = "test-support"))]
+ decorated_pane_ix: None,
}
}
Member::Axis(axis) => axis.render(basis + 1, zoomed, maximized, render_cx, window, cx),
@@ -997,7 +1005,7 @@ impl PaneAxis {
Member::Pane(pane) => {
is_leaf_pane[ix] = true;
if pane == render_cx.active_pane() {
- active_pane_ix = Some(ix);
+ active_pane_ix = pane.read(cx).has_focus(window, cx).then_some(ix);
contains_active_pane = true;
}
}
@@ -1029,6 +1037,8 @@ impl PaneAxis {
PaneRenderResult {
element,
contains_active_pane,
+ #[cfg(any(test, feature = "test-support"))]
+ decorated_pane_ix: active_pane_ix,
}
}
}
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index ab9c1d06508..525a3d4d29b 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -14140,6 +14140,89 @@ mod tests {
})
}
+ fn render_center_group(
+ workspace: &Workspace,
+ window: &mut Window,
+ cx: &mut App,
+ ) -> pane_group::PaneRenderResult {
+ workspace.center.root.render(
+ 0,
+ None,
+ None,
+ &PaneRenderContext {
+ follower_states: &workspace.follower_states,
+ active_call: workspace.active_call(),
+ active_pane: &workspace.active_pane,
+ app_state: &workspace.app_state,
+ project: &workspace.project,
+ workspace: &workspace.weak_self,
+ },
+ window,
+ cx,
+ )
+ }
+
+ #[gpui::test]
+ async fn test_active_pane_decorations_follow_window_focus(cx: &mut gpui::TestAppContext) {
+ init_test(cx);
+ let fs = FakeFs::new(cx.executor());
+ let project = Project::test(fs, None, cx).await;
+ let (workspace, cx) =
+ cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
+
+ // Decorations are only painted for splits, so a second pane is needed.
+ add_an_item_to_active_pane(cx, &workspace, 1);
+ let second_pane = split_pane(cx, &workspace);
+ add_an_item_to_active_pane(cx, &workspace, 2);
+
+ let panel = workspace.update_in(cx, |workspace, window, cx| {
+ let panel = cx.new(|cx| TestPanel::new(DockPosition::Left, 0, cx));
+ workspace.add_panel(panel.clone(), window, cx);
+ panel
+ });
+ cx.run_until_parked();
+
+ workspace.update_in(cx, |workspace, window, cx| {
+ assert_eq!(workspace.active_pane(), &second_pane);
+ let result = render_center_group(workspace, window, cx);
+ assert!(result.contains_active_pane);
+ assert_eq!(
+ result.decorated_pane_ix,
+ Some(1),
+ "the active pane should be decorated while it has focus"
+ );
+ });
+
+ workspace.update_in(cx, |workspace, window, cx| {
+ workspace.toggle_panel_focus::<TestPanel>(window, cx);
+ });
+ cx.run_until_parked();
+ workspace.update_in(cx, |_, window, cx| {
+ assert!(panel.focus_handle(cx).is_focused(window));
+ });
+
+ workspace.update_in(cx, |workspace, window, cx| {
+ assert_eq!(workspace.active_pane(), &second_pane);
+ let result = render_center_group(workspace, window, cx);
+ assert!(result.contains_active_pane);
+ assert_eq!(
+ result.decorated_pane_ix, None,
+ "an unfocused group should not decorate its active pane"
+ );
+ });
+
+ workspace.update_in(cx, |workspace, window, cx| {
+ let focus_handle = workspace.active_pane().read(cx).focus_handle(cx);
+ window.focus(&focus_handle, cx);
+ });
+ cx.run_until_parked();
+
+ workspace.update_in(cx, |workspace, window, cx| {
+ let result = render_center_group(workspace, window, cx);
+ assert_eq!(result.decorated_pane_ix, Some(1));
+ });
+ }
+
#[gpui::test]
async fn test_join_all_panes(cx: &mut gpui::TestAppContext) {
init_test(cx);