Maintain panel visibility when changing its position

This commit is contained in:
Antonio Scandurra 2023-05-10 11:06:37 +02:00
parent 6e3ce6332a
commit 8fa379bbc5
2 changed files with 35 additions and 6 deletions

View file

@ -187,8 +187,22 @@ impl Dock {
}
pub fn remove_panel<T: Panel>(&mut self, panel: &ViewHandle<T>, cx: &mut ViewContext<Self>) {
self.panels.retain(|entry| entry.panel.id() != panel.id());
cx.notify();
if let Some(panel_ix) = self
.panels
.iter()
.position(|item| item.panel.id() == panel.id())
{
if panel_ix == self.active_item_ix {
self.active_item_ix = 0;
cx.emit(Event::Close);
}
self.panels.remove(panel_ix);
cx.notify();
}
}
pub fn panels_len(&self) -> usize {
self.panels.len()
}
pub fn activate_item(&mut self, item_ix: usize, cx: &mut ViewContext<Self>) {