project_panel: Fix worktree root rename (#24487)
Closes #7923 This PR fixes root worktree renaming by: 1. Handling the case where `new_path` is the new root name instead of a relative path from the root. 2. [#20313](https://github.com/zed-industries/zed/pull/20313) added functionality to watch for root worktree renames made externally, e.g., via Finder. This PR avoids relying on that watcher because, when renaming explicitly from Zed, we can eagerly perform the necessary work (of course after fs rename) instead of waiting for the watcher to detect the rename. This prevents UI glitches during renaming root. Todo: - [x] Fix wrong abs paths when root is renamed - [x] Fix explicit scan entry func to handle renamed root dir - [x] Tests - [x] Test on Linux - [x] Tested with single and multipe worktrees - [x] Tested when single file is root file Release Notes: - Fixed an issue where worktree root name couldn't be renamed in project panel.
This commit is contained in:
parent
4207b194e3
commit
f1693e6129
3 changed files with 143 additions and 17 deletions
|
@ -733,7 +733,9 @@ impl ProjectPanel {
|
|||
.action("Copy Path", Box::new(CopyPath))
|
||||
.action("Copy Relative Path", Box::new(CopyRelativePath))
|
||||
.separator()
|
||||
.action("Rename", Box::new(Rename))
|
||||
.when(!is_root || !cfg!(target_os = "windows"), |menu| {
|
||||
menu.action("Rename", Box::new(Rename))
|
||||
})
|
||||
.when(!is_root & !is_remote, |menu| {
|
||||
menu.action("Trash", Box::new(Trash { skip_prompt: false }))
|
||||
})
|
||||
|
@ -1348,6 +1350,10 @@ impl ProjectPanel {
|
|||
if let Some(worktree) = self.project.read(cx).worktree_for_id(worktree_id, cx) {
|
||||
let sub_entry_id = self.unflatten_entry_id(entry_id);
|
||||
if let Some(entry) = worktree.read(cx).entry_for_id(sub_entry_id) {
|
||||
#[cfg(target_os = "windows")]
|
||||
if Some(entry) == worktree.read(cx).root_entry() {
|
||||
return;
|
||||
}
|
||||
self.edit_state = Some(EditState {
|
||||
worktree_id,
|
||||
entry_id: sub_entry_id,
|
||||
|
@ -7280,6 +7286,84 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
async fn test_rename_root_of_worktree(cx: &mut gpui::TestAppContext) {
|
||||
init_test_with_editor(cx);
|
||||
|
||||
let fs = FakeFs::new(cx.executor().clone());
|
||||
fs.insert_tree(
|
||||
"/root1",
|
||||
json!({
|
||||
"dir1": {
|
||||
"file1.txt": "content 1",
|
||||
},
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/root1".as_ref()], cx).await;
|
||||
let workspace =
|
||||
cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
let cx = &mut VisualTestContext::from_window(*workspace, cx);
|
||||
let panel = workspace.update(cx, ProjectPanel::new).unwrap();
|
||||
|
||||
toggle_expand_dir(&panel, "root1/dir1", cx);
|
||||
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..20, cx),
|
||||
&["v root1", " v dir1 <== selected", " file1.txt",],
|
||||
"Initial state with worktrees"
|
||||
);
|
||||
|
||||
select_path(&panel, "root1", cx);
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..20, cx),
|
||||
&["v root1 <== selected", " v dir1", " file1.txt",],
|
||||
);
|
||||
|
||||
// Rename root1 to new_root1
|
||||
panel.update_in(cx, |panel, window, cx| panel.rename(&Rename, window, cx));
|
||||
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..20, cx),
|
||||
&[
|
||||
"v [EDITOR: 'root1'] <== selected",
|
||||
" v dir1",
|
||||
" file1.txt",
|
||||
],
|
||||
);
|
||||
|
||||
let confirm = panel.update_in(cx, |panel, window, cx| {
|
||||
panel
|
||||
.filename_editor
|
||||
.update(cx, |editor, cx| editor.set_text("new_root1", window, cx));
|
||||
panel.confirm_edit(window, cx).unwrap()
|
||||
});
|
||||
confirm.await.unwrap();
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..20, cx),
|
||||
&[
|
||||
"v new_root1 <== selected",
|
||||
" v dir1",
|
||||
" file1.txt",
|
||||
],
|
||||
"Should update worktree name"
|
||||
);
|
||||
|
||||
// Ensure internal paths have been updated
|
||||
select_path(&panel, "new_root1/dir1/file1.txt", cx);
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..20, cx),
|
||||
&[
|
||||
"v new_root1",
|
||||
" v dir1",
|
||||
" file1.txt <== selected",
|
||||
],
|
||||
"Files in renamed worktree are selectable"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_multiple_marked_entries(cx: &mut gpui::TestAppContext) {
|
||||
init_test_with_editor(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue