Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

workspace: Sanitize pinned tab count before usage (#21417)

Piotr Osiewiczf32ffcf5bb00
diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs
index 83cc911a91b..fe6b08fd4a8 100644
--- a/crates/workspace/src/pane.rs
+++ b/crates/workspace/src/pane.rs
@@ -1890,7 +1890,7 @@ impl Pane {
fn unpin_tab_at(&mut self, ix: usize, cx: &mut ViewContext<'_, Self>) {
maybe!({
let pane = cx.view().clone();
- self.pinned_tab_count = self.pinned_tab_count.checked_sub(1).unwrap();
+ self.pinned_tab_count = self.pinned_tab_count.checked_sub(1)?;
let destination_index = self.pinned_tab_count;
let id = self.item_for_index(ix)?.item_id();
diff --git a/crates/workspace/src/persistence/model.rs b/crates/workspace/src/persistence/model.rs
index a2510b8bec6..7a368ee4411 100644
--- a/crates/workspace/src/persistence/model.rs
+++ b/crates/workspace/src/persistence/model.rs
@@ -473,7 +473,7 @@ impl SerializedPane {
})?;
}
pane.update(cx, |pane, _| {
- pane.set_pinned_count(self.pinned_count);
+ pane.set_pinned_count(self.pinned_count.min(items.len()));
})?;
anyhow::Ok(items)