project_panel: Improve behavior for cut-pasting entries (#31931)

Previously, we would move entries each time they were pasted. Thus, if
you were to cut some files and pasted them in folder `a` and then `b`,
they would only occur in folder `b` and not in folder `a`. This is
unintuitive - e.g. the same does not apply to text and does not happen
in other editors.

This PR improves this behavior - after the first paste of a cut
clipboard, we change the clipboard to a copy clipboard, ensuring that
for all folloing pastes, the entries are not moved again. In the above
example, the files would then also be found in folder `a`. This is also
reflected in the added test.

Release Notes:

- Ensured that cut project panel entries are cut-pasted only on the
first use, and copy-pasted on all subsequent pastes.
This commit is contained in:
Finn Evers 2025-06-03 09:51:42 +02:00 committed by GitHub
parent 2bb8aa2f73
commit 657c8b1084
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 97 additions and 0 deletions

View file

@ -2343,6 +2343,11 @@ impl ProjectPanel {
})
.detach_and_log_err(cx);
if clip_is_cut {
// Convert the clipboard cut entry to a copy entry after the first paste.
self.clipboard = self.clipboard.take().map(ClipboardEntry::to_copy_entry);
}
self.expand_entry(worktree_id, entry.id, cx);
Some(())
});
@ -5033,6 +5038,13 @@ impl ClipboardEntry {
ClipboardEntry::Copied(entries) | ClipboardEntry::Cut(entries) => entries,
}
}
fn to_copy_entry(self) -> Self {
match self {
ClipboardEntry::Copied(_) => self,
ClipboardEntry::Cut(entries) => ClipboardEntry::Copied(entries),
}
}
}
#[cfg(test)]