diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index 42eb754c21347e7dced792f3e56cb9901bc70bd1..bb4b10fa63dc884b8cf0ab8eee8e3bc34880b2a5 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -883,8 +883,14 @@ impl ItemHandle for Entity { 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); + } } }, )