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

+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]