Compare commits

...

2 Commits

Author SHA1 Message Date
Cole Miller
cc5adeb83b clippy 2025-03-19 11:21:13 -04:00
Cole Miller
c91efd0e50 WIP 2025-03-18 18:51:44 -04:00
3 changed files with 48 additions and 2 deletions

View File

@@ -875,7 +875,20 @@ impl GitPanel {
}
};
if entry.worktree_path.starts_with("..") {
let should_open_single_path = entry.worktree_path.starts_with("..")
|| self
.workspace
.update(cx, |workspace, cx| {
workspace
.item_of_type::<ProjectDiff>(cx)
.map_or(false, |project_diff| {
project_diff
.read(cx)
.has_excerpt_for_path(&entry.repo_path.0, cx)
})
})
.unwrap_or(false);
if should_open_single_path {
self.workspace
.update(cx, |workspace, cx| {
workspace

View File

@@ -26,7 +26,11 @@ use project::{
git::{GitEvent, GitStore},
Project, ProjectPath,
};
use std::any::{Any, TypeId};
use std::{
any::{Any, TypeId},
path::Path,
sync::Arc,
};
use theme::ActiveTheme;
use ui::{prelude::*, vertical_divider, KeyBinding, Tooltip};
use util::ResultExt as _;
@@ -65,6 +69,9 @@ const CONFLICT_NAMESPACE: &'static str = "0";
const TRACKED_NAMESPACE: &'static str = "1";
const NEW_NAMESPACE: &'static str = "2";
const MAX_DIFF_TRACKED_PATHS: usize = 1000;
const MAX_DIFF_UNTRACKED_PATHS: usize = 1000;
impl ProjectDiff {
pub(crate) fn register(workspace: &mut Workspace, cx: &mut Context<Workspace>) {
workspace.register_action(Self::deploy);
@@ -339,6 +346,7 @@ impl ProjectDiff {
let mut result = vec![];
repo.update(cx, |repo, cx| {
let (mut tracked_count, mut untracked_count) = (0, 0);
for entry in repo.status() {
if !entry.status.has_changes() {
continue;
@@ -346,11 +354,24 @@ impl ProjectDiff {
let Some(project_path) = repo.repo_path_to_project_path(&entry.repo_path) else {
continue;
};
let namespace = if repo.has_conflict(&entry.repo_path) {
if tracked_count >= MAX_DIFF_TRACKED_PATHS {
continue;
}
tracked_count += 1;
CONFLICT_NAMESPACE
} else if entry.status.is_created() {
if untracked_count >= MAX_DIFF_UNTRACKED_PATHS {
continue;
}
untracked_count += 1;
NEW_NAMESPACE
} else {
if tracked_count >= MAX_DIFF_TRACKED_PATHS {
continue;
}
tracked_count += 1;
TRACKED_NAMESPACE
};
let path_key = PathKey::namespaced(namespace, entry.repo_path.0.clone());
@@ -482,6 +503,14 @@ impl ProjectDiff {
Ok(())
}
pub fn has_excerpt_for_path(&self, path: &Arc<Path>, cx: &App) -> bool {
let multibuffer = self.multibuffer.read(cx);
multibuffer.has_excerpt_for_path(&PathKey::namespaced(CONFLICT_NAMESPACE, path.clone()))
|| multibuffer
.has_excerpt_for_path(&PathKey::namespaced(TRACKED_NAMESPACE, path.clone()))
|| multibuffer.has_excerpt_for_path(&PathKey::namespaced(NEW_NAMESPACE, path.clone()))
}
#[cfg(any(test, feature = "test-support"))]
pub fn excerpt_paths(&self, cx: &App) -> Vec<String> {
self.multibuffer

View File

@@ -1596,6 +1596,10 @@ impl MultiBuffer {
self.update_path_excerpts(path, buffer, &buffer_snapshot, new, cx)
}
pub fn has_excerpt_for_path(&self, path: &PathKey) -> bool {
self.excerpts_by_path.contains_key(path)
}
fn update_path_excerpts(
&mut self,
path: PathKey,