Dock: fix crash dragging a pallet that is alone in its group

Dragging a pallet over its own group (e.g. the block palette, alone on
the right edge) targeted joining that group. Joining first detached the
pallet, which removed the now-empty group, then indexed it: an
out-of-bounds panic, hit already by the live drop preview. A pallet alone
in the group it would join now just stays put.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013RyGiMXcsf9HTKfqDxaQGt
This commit is contained in:
Claude committed 2026-10-09 19:29:37 +00:00
1 parent 258762f992
commit 77ddc59df3
2 files changed
+36

No files matched your search

+25
View File
@@ -2111,6 +2111,31 @@ mod tests {
);
}
#[test]
fn dock_dragging_a_lone_pallet_over_its_own_group_is_a_no_op() {
use crate::app::config::DockSide;
use crate::ui::dock::{DropTarget, PanelId};
let mut app = dock_app();
let before = app.dock.clone();
// The right edge's only group holds just the block palette; drag it
// around over itself.
let target = drag_panel(
&mut app,
PanelId::BlockPalette,
iced::Point::new(1500.0, 10.0),
iced::Point::new(1450.0, 600.0),
);
assert_eq!(
target,
Some(DropTarget::Join {
side: DockSide::Right,
group: 0,
index: 1
})
);
assert_eq!(app.dock, before);
}
#[test]
fn dock_click_without_drag_changes_nothing() {
let mut app = dock_app();
+11
View File
@@ -557,6 +557,11 @@ impl DockState {
if group >= self.groups(side).len() {
return false;
}
// A pallet alone in its group has nowhere to move within it (and
// detaching it would remove the group being joined).
if self.groups(side)[group].panels == [id] {
return self.show_group(side, group);
}
let before = self.clone();
let width = self.group_width(side, group);
let joining = !self.groups(side)[group].panels.contains(&id);
@@ -1086,6 +1091,12 @@ mod tests {
assert_eq!(state.left[0].panels[0], PanelId::BlockPalette);
// Dropping it where it already is changes nothing.
assert!(!state.join_group(PanelId::BlockPalette, DockSide::Left, 0, 1));
// Nor does dropping a pallet that is alone in its group onto it.
state.dock(PanelId::Count, DockSide::Right, 0);
for index in 0..=1 {
assert!(!state.join_group(PanelId::Count, DockSide::Right, 0, index));
}
assert_eq!(state.right[0].panels, vec![PanelId::Count]);
}
#[test]