Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7306,6 +7306,7 @@ pub struct OpenOptions {
pub visible: Option<OpenVisible>,
pub focus: Option<bool>,
pub open_new_workspace: Option<bool>,
pub prefer_focused_window: bool,
pub replace_window: Option<WindowHandle<Workspace>>,
pub env: Option<HashMap<String, String>>,
}
Expand Down Expand Up @@ -7358,7 +7359,7 @@ pub fn open_paths(
})?;

if open_options.open_new_workspace.is_none()
&& existing.is_none()
&& (existing.is_none() || open_options.prefer_focused_window)
&& all_metadatas.iter().all(|file| !file.is_dir)
{
cx.update(|cx| {
Expand Down
59 changes: 59 additions & 0 deletions crates/zed/src/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5066,4 +5066,63 @@ mod tests {
"BUG FOUND: Project settings were overwritten when opening via command - original custom content was lost"
);
}

#[gpui::test]
async fn test_prefer_focused_window(cx: &mut gpui::TestAppContext) {
let app_state = init_test(cx);
let paths = [PathBuf::from(path!("/dir/document.txt"))];

app_state
.fs
.as_fake()
.insert_tree(
path!("/dir"),
json!({
"document.txt": "Some of the documentation's content."
}),
)
.await;

let project_a = Project::test(app_state.fs.clone(), [path!("/dir").as_ref()], cx).await;
let window_a =
cx.add_window(|window, cx| Workspace::test_new(project_a.clone(), window, cx));

let project_b = Project::test(app_state.fs.clone(), [path!("/dir").as_ref()], cx).await;
let window_b =
cx.add_window(|window, cx| Workspace::test_new(project_b.clone(), window, cx));

let project_c = Project::test(app_state.fs.clone(), [path!("/dir").as_ref()], cx).await;
let window_c =
cx.add_window(|window, cx| Workspace::test_new(project_c.clone(), window, cx));

for window in [window_a, window_b, window_c] {
let _ = cx.update_window(*window, |_, window, _| {
window.activate_window();
});

cx.update(|cx| {
let open_options = OpenOptions {
prefer_focused_window: true,
..Default::default()
};

workspace::open_paths(&paths, app_state.clone(), open_options, cx)
})
.await
.unwrap();

cx.update_window(*window, |_, window, _| assert!(window.is_window_active()))
.unwrap();

let _ = window.read_with(cx, |workspace, cx| {
let pane = workspace.active_pane().read(cx);
let project_path = pane.active_item().unwrap().project_path(cx).unwrap();

assert_eq!(
project_path.path.as_ref().as_std_path().to_str().unwrap(),
path!("document.txt")
)
});
}
}
}
1 change: 1 addition & 0 deletions crates/zed/src/zed/open_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ async fn open_local_workspace(
workspace::OpenOptions {
open_new_workspace: effective_open_new_workspace,
replace_window,
prefer_focused_window: wait,
env: env.cloned(),
..Default::default()
},
Expand Down
Loading