Git improvements (#24238)
- **Base diffs on uncommitted changes** - **Show added files in project diff view** - **Fix git panel optimism** Release Notes: - Git: update diffs to be relative to HEAD instead of the index; to pave the way for showing which hunks are staged --------- Co-authored-by: Cole <cole@zed.dev>
This commit is contained in:
parent
22b7042b9e
commit
0963401a8d
11 changed files with 241 additions and 231 deletions
|
@ -67,7 +67,7 @@ pub struct MultiBuffer {
|
|||
/// Contains the state of the buffers being edited
|
||||
buffers: RefCell<HashMap<BufferId, BufferState>>,
|
||||
// only used by consumers using `set_excerpts_for_buffer`
|
||||
buffers_by_path: BTreeMap<Arc<Path>, Vec<ExcerptId>>,
|
||||
buffers_by_path: BTreeMap<PathKey, Vec<ExcerptId>>,
|
||||
diff_bases: HashMap<BufferId, ChangeSetState>,
|
||||
all_diff_hunks_expanded: bool,
|
||||
subscriptions: Topic,
|
||||
|
@ -143,6 +143,15 @@ impl MultiBufferDiffHunk {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Ord, PartialOrd, Clone, Hash, Debug)]
|
||||
pub struct PathKey(String);
|
||||
|
||||
impl PathKey {
|
||||
pub fn namespaced(namespace: &str, path: &Path) -> Self {
|
||||
Self(format!("{}/{}", namespace, path.to_string_lossy()))
|
||||
}
|
||||
}
|
||||
|
||||
pub type MultiBufferPoint = Point;
|
||||
type ExcerptOffset = TypedOffset<Excerpt>;
|
||||
type ExcerptPoint = TypedPoint<Excerpt>;
|
||||
|
@ -1395,7 +1404,7 @@ impl MultiBuffer {
|
|||
anchor_ranges
|
||||
}
|
||||
|
||||
pub fn location_for_path(&self, path: &Arc<Path>, cx: &App) -> Option<Anchor> {
|
||||
pub fn location_for_path(&self, path: &PathKey, cx: &App) -> Option<Anchor> {
|
||||
let excerpt_id = self.buffers_by_path.get(path)?.first()?;
|
||||
let snapshot = self.snapshot(cx);
|
||||
let excerpt = snapshot.excerpt(*excerpt_id)?;
|
||||
|
@ -1408,7 +1417,7 @@ impl MultiBuffer {
|
|||
|
||||
pub fn set_excerpts_for_path(
|
||||
&mut self,
|
||||
path: Arc<Path>,
|
||||
path: PathKey,
|
||||
buffer: Entity<Buffer>,
|
||||
ranges: Vec<Range<Point>>,
|
||||
context_line_count: u32,
|
||||
|
@ -1517,11 +1526,11 @@ impl MultiBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn paths(&self) -> impl Iterator<Item = Arc<Path>> + '_ {
|
||||
pub fn paths(&self) -> impl Iterator<Item = PathKey> + '_ {
|
||||
self.buffers_by_path.keys().cloned()
|
||||
}
|
||||
|
||||
pub fn remove_excerpts_for_path(&mut self, path: Arc<Path>, cx: &mut Context<Self>) {
|
||||
pub fn remove_excerpts_for_path(&mut self, path: PathKey, cx: &mut Context<Self>) {
|
||||
if let Some(to_remove) = self.buffers_by_path.remove(&path) {
|
||||
self.remove_excerpts(to_remove, cx)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use language::{Buffer, Rope};
|
|||
use parking_lot::RwLock;
|
||||
use rand::prelude::*;
|
||||
use settings::SettingsStore;
|
||||
use std::{env, path::PathBuf};
|
||||
use std::env;
|
||||
use util::test::sample_text;
|
||||
|
||||
#[ctor::ctor]
|
||||
|
@ -1596,7 +1596,7 @@ fn test_set_excerpts_for_buffer(cx: &mut TestAppContext) {
|
|||
cx,
|
||||
)
|
||||
});
|
||||
let path1: Arc<Path> = Arc::from(PathBuf::from("path1"));
|
||||
let path1: PathKey = PathKey::namespaced("0", Path::new("/"));
|
||||
let buf2 = cx.new(|cx| {
|
||||
Buffer::local(
|
||||
indoc! {
|
||||
|
@ -1615,7 +1615,7 @@ fn test_set_excerpts_for_buffer(cx: &mut TestAppContext) {
|
|||
cx,
|
||||
)
|
||||
});
|
||||
let path2: Arc<Path> = Arc::from(PathBuf::from("path2"));
|
||||
let path2 = PathKey::namespaced("x", Path::new("/"));
|
||||
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
multibuffer.update(cx, |multibuffer, cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue