workspace: Fix context menu triggering format on save#44073
Merged
SomeoneToIgnore merged 1 commit intozed-industries:mainfrom Dec 16, 2025
Merged
workspace: Fix context menu triggering format on save#44073SomeoneToIgnore merged 1 commit intozed-industries:mainfrom
SomeoneToIgnore merged 1 commit intozed-industries:mainfrom
Conversation
Contributor
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
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:
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.
Contributor
|
@SomeoneToIgnore off-topic, but what font is that in your screenshot? 😅 |
Contributor
SomeoneToIgnore
approved these changes
Dec 16, 2025
Contributor
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #43989
Release Notes: