From d1af5f656ac275708b777736bdcbf5d220b38fe2 Mon Sep 17 00:00:00 2001 From: Deng Liu Date: Fri, 27 Nov 2026 15:02:55 -0800 Subject: [PATCH] fix(windows): include remote development windows in Merge All Project Windows (#6593) Merge All Project Windows only collected windows with a local project, so remote development windows were left out. Candidates now include every local or remote project window (welcome and LightEdit windows stay out), selected by a unit-tested merge_candidates helper in ide-workspace. A member that shares a native tab group or frame with a window outside the merge is split from it first, so that window is neither pulled in nor left hidden. Co-authored-by: dengliu <5108773+dengliu@users.noreply.github.com> --- crates/ide-workspace/src/window_groups.rs | 27 +++++++++++ src-tauri/src/window_groups.rs | 58 +++++++++++++++++++++-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/crates/ide-workspace/src/window_groups.rs b/crates/ide-workspace/src/window_groups.rs index 53b61d1ae2..d5f7e91c87 100644 --- a/crates/ide-workspace/src/window_groups.rs +++ b/crates/ide-workspace/src/window_groups.rs @@ -3,6 +3,16 @@ use ide_core::{IdeError, IdeResult}; use serde::{Deserialize, Serialize}; use std::path::PathBuf; +/// Selects every open project window eligible to merge with `caller`. +/// `is_project` returns `true` for open local or remote project windows and `false` for +/// non-project windows (welcome screen, LightEdit). +pub fn merge_candidates(windows: &[String], caller: &str, is_project: impl Fn(&str) -> bool) -> Vec { + if !is_project(caller) { + return Vec::new(); + } + windows.iter().filter(|label| is_project(label)).cloned().collect() +} + /// Platform adapters supply the system's tab preference and active project state. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum TabbingPreference { @@ -269,4 +279,21 @@ mod tests { // A grouped window still opening its project: keep the previous session. assert_eq!(session(&groups, &windows, |l| (l != "project-2").then(|| PathBuf::from(l))), None); } + + #[test] + fn merge_candidates_includes_local_and_remote_project_windows() { + let windows = members(&["local-1", "local-2", "ssh-a-1", "ssh-b-1", "welcome", "light"]); + let is_project = |label: &str| matches!(label, "local-1" | "local-2" | "ssh-a-1" | "ssh-b-1"); + + assert_eq!( + merge_candidates(&windows, "local-1", is_project), + members(&["local-1", "local-2", "ssh-a-1", "ssh-b-1"]) + ); + assert_eq!( + merge_candidates(&windows, "ssh-a-1", is_project), + members(&["local-1", "local-2", "ssh-a-1", "ssh-b-1"]) + ); + assert!(merge_candidates(&windows, "welcome", is_project).is_empty()); + assert!(merge_candidates(&windows, "light", is_project).is_empty()); + } } diff --git a/src-tauri/src/window_groups.rs b/src-tauri/src/window_groups.rs index eb85b584d0..9411a8cba5 100644 --- a/src-tauri/src/window_groups.rs +++ b/src-tauri/src/window_groups.rs @@ -16,6 +16,11 @@ mod frames; type Group = ide_workspace::window_groups::WindowGroup; +fn is_project_window(app: &AppHandle, label: &str) -> bool { + let state = app.state::(); + state.remote_dev.get(label).is_some() || state.project(label).is_ok_and(|p| !p.light) +} + #[derive(Clone, Serialize, Deserialize, Type)] #[serde(rename_all = "camelCase")] pub struct WindowTab { @@ -134,10 +139,9 @@ pub fn join(app: &AppHandle, anchor: &str, new_window: &str) -> IdeResult<()> { } pub fn merge(app: &AppHandle, caller: &str) -> IdeResult<()> { - let members = windows::project_window_labels(app) - .into_iter() - .filter(|label| app.state::().project(label).is_ok_and(|p| !p.light)) - .collect::>(); + let all_windows = windows::project_window_labels(app); + let members = + ide_workspace::window_groups::merge_candidates(&all_windows, caller, |label| is_project_window(app, label)); if members.len() < 2 || !members.iter().any(|label| label == caller) { return Err(IdeError::invalid("Open at least two project windows to create a window group")); } @@ -147,7 +151,51 @@ pub fn merge(app: &AppHandle, caller: &str) -> IdeResult<()> { window.set_fullscreen(false).map_err(|e| IdeError::internal(e.to_string()))?; } } - app.state::().groups.lock().merge(members, caller)?; + // If a member is currently grouped with a window outside `members` (e.g. a non-project + // window), separate it from that native/frame group before merging. + let state = app.state::(); + let member_set: HashSet<&str> = members.iter().map(String::as_str).collect(); + let (split_members, leftover_survivors): (Vec, Vec) = { + let groups = state.groups.lock(); + let mut split = Vec::new(); + let mut survivors = Vec::new(); + for group in groups.groups() { + let has_in = group.members.iter().any(|m| member_set.contains(m.as_str())); + let has_out = group.members.iter().any(|m| !member_set.contains(m.as_str())); + if has_in && has_out { + for m in &group.members { + if member_set.contains(m.as_str()) { + split.push(m.clone()); + } + } + if member_set.contains(group.selected.as_str()) + && let Some(survivor) = group.members.iter().find(|m| !member_set.contains(m.as_str())) + { + survivors.push(survivor.clone()); + } + } + } + (split, survivors) + }; + #[cfg(target_os = "macos")] + { + let _ = &leftover_survivors; + for label in &split_members { + if let Some(window) = app.get_webview_window(label) { + crate::macos::move_tab_to_new_window(&window).map_err(|e| IdeError::internal(e.to_string()))?; + } + } + } + #[cfg(not(target_os = "macos"))] + { + let _ = &split_members; + for label in &leftover_survivors { + if let Some(window) = app.get_webview_window(label) { + let _ = window.show(); + } + } + } + state.groups.lock().merge(members, caller)?; select(app, caller, caller) }