tiles: Fix panels get item out of bound error when removed some panel. (#675)

This commit is contained in:
Jason Lee 2025-02-28 18:53:25 +08:00 committed by GitHub
parent 9732c3b7e8
commit 76efa2715b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -847,13 +847,14 @@ impl Tiles {
// Handle dragging // Handle dragging
if let Some(index) = self.dragging_index { if let Some(index) = self.dragging_index {
if let Some(item) = self.panels.get(index) {
let initial_bounds = self.dragging_initial_bounds; let initial_bounds = self.dragging_initial_bounds;
let current_bounds = self.panels[index].bounds; let current_bounds = item.bounds;
if initial_bounds.origin != current_bounds.origin if initial_bounds.origin != current_bounds.origin
|| initial_bounds.size != current_bounds.size || initial_bounds.size != current_bounds.size
{ {
changes_to_push.push(TileChange { changes_to_push.push(TileChange {
tile_id: self.panels[index].panel.view().entity_id(), tile_id: item.panel.view().entity_id(),
old_bounds: Some(initial_bounds), old_bounds: Some(initial_bounds),
new_bounds: Some(current_bounds), new_bounds: Some(current_bounds),
old_order: None, old_order: None,
@ -862,15 +863,17 @@ impl Tiles {
}); });
} }
} }
}
// Handle resizing // Handle resizing
if let Some(index) = self.resizing_index { if let Some(index) = self.resizing_index {
if let Some(drag_data) = &self.resizing_drag_data { if let Some(drag_data) = &self.resizing_drag_data {
if let Some(item) = self.panels.get(index) {
let initial_bounds = drag_data.last_bounds; let initial_bounds = drag_data.last_bounds;
let current_bounds = self.panels[index].bounds; let current_bounds = item.bounds;
if initial_bounds.size != current_bounds.size { if initial_bounds.size != current_bounds.size {
changes_to_push.push(TileChange { changes_to_push.push(TileChange {
tile_id: self.panels[index].panel.view().entity_id(), tile_id: item.panel.view().entity_id(),
old_bounds: Some(initial_bounds), old_bounds: Some(initial_bounds),
new_bounds: Some(current_bounds), new_bounds: Some(current_bounds),
old_order: None, old_order: None,
@ -880,6 +883,7 @@ impl Tiles {
} }
} }
} }
}
// Push changes to history if any // Push changes to history if any
if !changes_to_push.is_empty() { if !changes_to_push.is_empty() {