Skip to content

workspace: Fix context menu triggering format on save#44073

Merged
SomeoneToIgnore merged 1 commit intozed-industries:mainfrom
flappyBug:main
Dec 16, 2025
Merged

workspace: Fix context menu triggering format on save#44073
SomeoneToIgnore merged 1 commit intozed-industries:mainfrom
flappyBug:main

Conversation

@flappyBug
Copy link
Contributor

@flappyBug flappyBug commented Dec 3, 2025

Closes #43989

Release Notes:

  • Fixed editor context menu triggering format on save

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 3, 2025
@maxdeviant maxdeviant changed the title workspace: fix context menu triggers format on save workspace: Fix context menu triggering format on save Dec 3, 2025
Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the catch.

Given that there's an action editor: open context menu, it means we can trigger this behavior in the test, as sure we can set the corresponding autoformatting settings in the test.

There's a bunch of formatting tests:

Image

we should take one as a base and test it, as this is quite subtle and formatting bugs may be frustrating when they regress.

Happy to merge it right after such test that fails on main and works in this branch.

@SomeoneToIgnore SomeoneToIgnore self-assigned this Dec 4, 2025
@errmayank
Copy link
Contributor

@SomeoneToIgnore off-topic, but what font is that in your screenshot? 😅

@SomeoneToIgnore
Copy link
Contributor

https://github.com/IdreesInc/Monocraft

Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had tried

diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index dfc8fd7f90..1286855307 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -12289,13 +12289,15 @@ async fn test_autosave_with_dirty_buffers(cx: &mut TestAppContext) {
     });
 
     let editor = cx.new_window_entity(|window, cx| {
-        Editor::new(
+        let mut editor = Editor::new(
             EditorMode::full(),
             multi_buffer,
             Some(project.clone()),
             window,
             cx,
-        )
+        );
+        editor.set_style(EditorStyle::default(), window, cx);
+        editor
     });
 
     // Edit only the first buffer
@@ -12387,6 +12389,49 @@ async fn test_autosave_with_dirty_buffers(cx: &mut TestAppContext) {
         0,
         "Buffer 3 should not have been written at all"
     );
+
+    cx.update(|_, cx| {
+        SettingsStore::update_global(cx, |store, cx| {
+            store.update_user_settings(cx, |settings| {
+                settings.workspace.autosave = Some(settings::AutosaveSetting::OnFocusChange);
+            });
+        });
+    });
+    editor.update_in(cx, |editor, window, cx| {
+        editor.change_selections(
+            SelectionEffects::scroll(Autoscroll::Next),
+            window,
+            cx,
+            |s| s.select_ranges(Some(MultiBufferOffset(10)..MultiBufferOffset(10))),
+        );
+        editor.insert("// edited", window, cx);
+    });
+    assert!(cx.read(|cx| editor.is_dirty(cx)));
+    dbg!(fs.write_count_for_path(path!("/dir/file1.rs")));
+    dbg!(fs.write_count_for_path(path!("/dir/file2.rs")));
+    dbg!(fs.write_count_for_path(path!("/dir/file3.rs")));
+
+    editor.update_in(cx, |editor, window, cx| {
+        editor.open_context_menu(&OpenContextMenu, window, cx);
+    });
+    cx.condition(&editor, |editor, _| editor.mouse_context_menu.is_some())
+        .await;
+    editor.update_in(cx, |editor, window, cx| {
+        window.focus(
+            &editor
+                .mouse_context_menu
+                .as_ref()
+                .unwrap()
+                .context_menu
+                .focus_handle(cx),
+        );
+    });
+    cx.executor().advance_clock(Duration::from_millis(2000));
+    cx.run_until_parked();
+    // assert!(!cx.read(|cx| editor.is_dirty(cx)));
+    dbg!(fs.write_count_for_path(path!("/dir/file1.rs")));
+    dbg!(fs.write_count_for_path(path!("/dir/file2.rs")));
+    dbg!(fs.write_count_for_path(path!("/dir/file3.rs")));
 }
 
 async fn setup_range_format_test(
diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs
index 42eb754c21..673cecc9e0 100644
--- a/crates/workspace/src/item.rs
+++ b/crates/workspace/src/item.rs
@@ -880,6 +880,7 @@ impl<T: Item> ItemHandle for Entity<T> {
                 &self.read(cx).focus_handle(cx),
                 window,
                 move |workspace, window, cx| {
+                    dbg!("???");
                     if let Some(item) = weak_item.upgrade()
                         && item.workspace_settings(cx).autosave == AutosaveSetting::OnFocusChange
                     {

but apparently our test suite has some issues with focus handling.

@SomeoneToIgnore SomeoneToIgnore merged commit f760233 into zed-industries:main Dec 16, 2025
26 checks passed
@github-project-automation github-project-automation bot moved this from Community PRs to Done in Quality Week – December 2025 Dec 16, 2025
CherryWorm pushed a commit to CherryWorm/zed that referenced this pull request Dec 16, 2025
…#44073)

Closes zed-industries#43989

Release Notes:

- Fixed editor context menu triggering format on save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

Development

Successfully merging this pull request may close these issues.

Right-click context menu triggers format on save with Auto Save on Focus Change, causing cursor jitter

3 participants