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.

project_panel: Avoid recording record excluded files changes (#61106)

Dino819fe3379995
diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs
index c621c47156c..61773c75178 100644
--- a/crates/project_panel/src/project_panel.rs
+++ b/crates/project_panel/src/project_panel.rs
@@ -1980,18 +1980,6 @@ impl ProjectPanel {
let new_entry = edit_task.await;
project_panel.update(cx, |project_panel, cx| {
project_panel.state.edit_state = None;
-
- // Record the operation if the edit was applied
- if new_entry.is_ok() {
- let operation = if let Some(old_entry) = edited_entry {
- Change::Renamed((worktree_id, old_entry.path).into(), new_project_path)
- } else {
- Change::Created(new_project_path)
- };
-
- project_panel.undo_manager.record([operation]).log_err();
- }
-
cx.notify();
})?;
@@ -2007,6 +1995,23 @@ impl ProjectPanel {
}
Ok(CreatedEntry::Included(new_entry)) => {
project_panel.update_in(cx, |project_panel, window, cx| {
+ // Only recording changes in included files as otherwise
+ // undoing some operations would fail, as
+ // `Worktree::entry_for_path` would return `None` for
+ // excluded paths.
+ // In the future we can look into adding support for recording
+ // changes in excluded paths, but that would mean updating
+ // methods that rely on `EntryId` to now rely on the actual
+ // paths.
+ let operation = match edited_entry {
+ Some(old_entry) => {
+ let project_path = (worktree_id, old_entry.path).into();
+ Change::Renamed(project_path, new_project_path)
+ }
+ None => Change::Created(new_project_path),
+ };
+ project_panel.undo_manager.record([operation]).log_err();
+
if let Some(selection) = &mut project_panel.selection
&& selection.entry_id == edited_entry_id
{
diff --git a/crates/project_panel/src/project_panel_tests.rs b/crates/project_panel/src/project_panel_tests.rs
index 3c6585cd746..0ab83a1cd3d 100644
--- a/crates/project_panel/src/project_panel_tests.rs
+++ b/crates/project_panel/src/project_panel_tests.rs
@@ -11193,12 +11193,12 @@ fn ensure_no_open_items_and_panes(workspace: &Entity<Workspace>, cx: &mut Visual
});
}
-struct TestProjectItemView {
+pub(crate) struct TestProjectItemView {
focus_handle: FocusHandle,
path: ProjectPath,
}
-struct TestProjectItem {
+pub(crate) struct TestProjectItem {
path: ProjectPath,
}
diff --git a/crates/project_panel/src/tests/undo.rs b/crates/project_panel/src/tests/undo.rs
index 9f607d9c074..070b31de6a5 100644
--- a/crates/project_panel/src/tests/undo.rs
+++ b/crates/project_panel/src/tests/undo.rs
@@ -3,14 +3,15 @@
use client::proto;
use collections::HashSet;
use fs::{FakeFs, Fs};
-use gpui::{Entity, VisualTestContext};
+use gpui::{App, BorrowAppContext, Entity, VisualTestContext};
use project::Project;
use serde_json::{Value, json};
+use settings::SettingsStore;
use std::path::Path;
use std::sync::Arc;
-use workspace::MultiWorkspace;
+use workspace::{MultiWorkspace, register_project_item};
-use crate::project_panel_tests::{self, find_project_entry, select_path};
+use crate::project_panel_tests::{self, TestProjectItemView, find_project_entry, select_path};
use crate::{NewDirectory, NewFile, ProjectPanel, Redo, Rename, Trash, Undo};
struct TestContext {
@@ -251,6 +252,10 @@ impl TestContext {
TestContext { panel, fs, cx }
}
+
+ fn update_app<R>(&mut self, update: impl FnOnce(&mut App) -> R) -> R {
+ self.cx.cx.update(update)
+ }
}
#[gpui::test]
@@ -499,3 +504,42 @@ async fn undo_redo_unavailable_for_read_only_collab_guest(cx: &mut gpui::TestApp
assert!(!window.is_action_available_in(&crate::Redo, &focus_handle));
});
}
+
+#[gpui::test]
+async fn excluded_create_is_not_recorded(cx: &mut gpui::TestAppContext) {
+ let mut cx = TestContext::new_with_tree(
+ cx,
+ json!({
+ "a.txt": "",
+ "b.txt": ""
+ }),
+ )
+ .await;
+
+ cx.update_app(|cx| {
+ cx.update_global::<SettingsStore, _>(|store, cx| {
+ store.update_user_settings(cx, |settings| {
+ settings.project.worktree.file_scan_exclusions = Some(vec![
+ "**/token.secret".to_string(),
+ "**/banana.secret".to_string(),
+ ]);
+ });
+ });
+
+ register_project_item::<TestProjectItemView>(cx);
+ });
+
+ cx.rename("a.txt", "renamed.txt").await;
+ cx.create_file("token.secret").await;
+ cx.assert_fs_state_is(&["b.txt", "renamed.txt", "token.secret"]);
+
+ cx.undo().await;
+ cx.assert_fs_state_is(&["b.txt", "a.txt", "token.secret"]);
+
+ cx.rename("a.txt", "renamed.txt").await;
+ cx.rename("b.txt", "banana.secret").await;
+ cx.assert_fs_state_is(&["renamed.txt", "token.secret", "banana.secret"]);
+
+ cx.undo().await;
+ cx.assert_fs_state_is(&["a.txt", "token.secret", "banana.secret"]);
+}