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: Fix context menu triggering format on save (#44073)

Hourannf760233704f9
diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs
index 42eb754c213..bb4b10fa63d 100644
--- a/crates/workspace/src/item.rs
+++ b/crates/workspace/src/item.rs
@@ -883,8 +883,14 @@ impl<T: Item> ItemHandle for Entity<T> {
if let Some(item) = weak_item.upgrade()
&& item.workspace_settings(cx).autosave == AutosaveSetting::OnFocusChange
{
- Pane::autosave_item(&item, workspace.project.clone(), window, cx)
- .detach_and_log_err(cx);
+ // Only trigger autosave if focus has truly left the item.
+ // If focus is still within the item's hierarchy (e.g., moved to a context menu),
+ // don't trigger autosave to avoid unwanted formatting and cursor jumps.
+ let focus_handle = item.item_focus_handle(cx);
+ if !focus_handle.contains_focused(window, cx) {
+ Pane::autosave_item(&item, workspace.project.clone(), window, cx)
+ .detach_and_log_err(cx);
+ }
}
},
)