mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-01 18:54:26 +01:00
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.
This commit is contained in:
1 parent
14d9aa5bc3
commit
6bc22c8902
2 files changed
+28
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> = 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();
|
||||
|
||||
Reference in new issue
Block a user