workspace: Do not attempt to unnecessarily update jump list on invisible worktree updates (#47990)

Lukas Wirth created

Release Notes:

- N/A *or* Added/Fixed/Improved ...

Change summary

crates/workspace/src/workspace.rs | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

Detailed changes

crates/workspace/src/workspace.rs 🔗

@@ -1306,12 +1306,18 @@ impl Workspace {
                     this.collaborator_left(*peer_id, window, cx);
                 }
 
-                project::Event::WorktreeRemoved(_) | project::Event::WorktreeAdded(..) => {
+                &project::Event::WorktreeRemoved(id) | &project::Event::WorktreeAdded(id) => {
                     this.update_window_title(window, cx);
-                    this.serialize_workspace(window, cx);
-                    this.update_history(cx);
+                    if this
+                        .project()
+                        .read(cx)
+                        .worktree_for_id(id, cx)
+                        .is_some_and(|wt| wt.read(cx).is_visible())
+                    {
+                        this.serialize_workspace(window, cx);
+                        this.update_history(cx);
+                    }
                 }
-
                 project::Event::WorktreeUpdatedEntries(..) => {
                     this.update_window_title(window, cx);
                     this.serialize_workspace(window, cx);