From 6bc22c89023e2da97e96e84037b40b3920539cd4 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sat, 28 Nov 2026 17:04:53 +0100 Subject: [PATCH] fix(ui): dragging a group member to the edge of another group ungroups it move_tab_in_strip left a dragged tab in its old group when it landed next to a different group and not next to its own, so the tab carried group A's colour inside group B's run. It now joins a group only when dropped between two members of it (or next to its own group) and is ungrouped otherwise. Adds a unit test that drags a member of group A behind the last member of group B. --- crates/ui-egui/src/panes.rs | 3 ++- crates/ui-egui/src/tab_group.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 24a5641ff8..4a817f1d22 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -253,7 +253,8 @@ impl PdfCraftApp { self.views[new_idx].group = left_group; } else if old_group.is_some() && (left_group == old_group || right_group == old_group) { self.views[new_idx].group = old_group; - } else if left_group.is_none() && right_group.is_none() { + } else { + // Dropped outside its group, or at the edge of another one: not a member of either. self.views[new_idx].group = None; } } diff --git a/crates/ui-egui/src/tab_group.rs b/crates/ui-egui/src/tab_group.rs index c27d3d571f..a09c983b9d 100644 --- a/crates/ui-egui/src/tab_group.rs +++ b/crates/ui-egui/src/tab_group.rs @@ -561,6 +561,32 @@ mod tests { assert_eq!(app.session.get(app.views[1].id).unwrap().name, "doc1.pdf"); } + #[test] + fn dragging_a_member_to_the_edge_of_another_group_ungroups_it() { + let mut app = PdfCraftApp::for_unit_tests(); + let ctx = egui::Context::default(); + for name in ["a1.pdf", "a2.pdf", "b1.pdf", "b2.pdf"] { + app.open_bytes(&ctx, name, None, FIXTURE.to_vec()).unwrap(); + } + let a = app.create_tab_group("A".into(), TabGroupColor::Blue); + let b = app.create_tab_group("B".into(), TabGroupColor::Green); + app.add_tab_to_group(0, a); + app.add_tab_to_group(1, a); + app.add_tab_to_group(2, b); + app.add_tab_to_group(3, b); + + // Drag a1.pdf behind b2.pdf: it sits after group B's last member, so it joins neither + // group, and group A keeps a2.pdf. + let tabs = app.tabs_in(crate::panes::Place::Main); + app.move_tab_in_strip(0, &tabs, 3); + + let names: Vec = app.views.iter().map(|v| app.session.get(v.id).unwrap().name.clone()).collect(); + assert_eq!(names, ["a2.pdf", "b1.pdf", "b2.pdf", "a1.pdf"]); + assert_eq!(app.views[3].group, None); + assert_eq!(app.views[0].group, Some(a)); + assert_eq!(app.views[2].group, Some(b)); + } + #[test] fn moving_last_member_to_another_group_cleans_up_previous_group() { let mut app = PdfCraftApp::for_unit_tests();