From f760233704f927ea778b14bdb8121c085bf8b654 Mon Sep 17 00:00:00 2001 From: Hourann Date: Tue, 16 Dec 2025 15:32:25 +0800 Subject: [PATCH] workspace: Fix context menu triggering format on save (#44073) Closes #43989 Release Notes: - Fixed editor context menu triggering format on save --- crates/workspace/src/item.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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); + } } }, )