workspace: Fix pinned count when restoring panes with failed items

Kunall Banerjee created

When deserializing panes, some items may fail to load and become `None`.
The pinned count should only include successfully loaded items, not
the original count which may exceed the number of actual items.

Change summary

crates/workspace/src/persistence/model.rs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

Detailed changes

crates/workspace/src/persistence/model.rs 🔗

@@ -351,8 +351,17 @@ impl SerializedPane {
                 }
             })?;
         }
+
+        // `items` contains `None` for each item that failed to deserialize.
+        // Only `Some` entries are added to the pane above, so the pinned
+        // count must only count those — not the total serialized count.
+        let pinned_count = items
+            .iter()
+            .take(self.pinned_count)
+            .filter(|item| item.is_some())
+            .count();
         pane.update(cx, |pane, _| {
-            pane.set_pinned_count(self.pinned_count.min(items.len()));
+            pane.set_pinned_count(pinned_count);
         })?;
 
         anyhow::Ok(items)