mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 08:54:04 +00:00
Temporarily revert git panel diff editor feature (#22733)
The existing code was causing us to constantly re-scan files when anything changed in the project. Temporarily revert this as we're about to rework this entire UI with the new primitives. follow up to https://github.com/zed-industries/zed/pull/22329 Release Notes: - N/A --------- Co-authored-by: Cole <cole@zed.dev>
This commit is contained in:
parent
5ec924828e
commit
3c430af31a
7 changed files with 268 additions and 296 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -5178,11 +5178,8 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"collections",
|
"collections",
|
||||||
"db",
|
"db",
|
||||||
"editor",
|
|
||||||
"futures 0.3.31",
|
|
||||||
"git",
|
"git",
|
||||||
"gpui",
|
"gpui",
|
||||||
"language",
|
|
||||||
"menu",
|
"menu",
|
||||||
"project",
|
"project",
|
||||||
"schemars",
|
"schemars",
|
||||||
|
|
|
@ -16,11 +16,8 @@ path = "src/git_ui.rs"
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
collections.workspace = true
|
collections.workspace = true
|
||||||
db.workspace = true
|
db.workspace = true
|
||||||
editor.workspace = true
|
|
||||||
futures.workspace = true
|
|
||||||
git.workspace = true
|
git.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
language.workspace = true
|
|
||||||
menu.workspace = true
|
menu.workspace = true
|
||||||
project.workspace = true
|
project.workspace = true
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
use crate::{git_status_icon, settings::GitPanelSettings};
|
use crate::{git_status_icon, settings::GitPanelSettings};
|
||||||
use crate::{CommitAllChanges, CommitStagedChanges, DiscardAll, StageAll, UnstageAll};
|
use crate::{CommitAllChanges, CommitStagedChanges, DiscardAll, StageAll, UnstageAll};
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::Result;
|
||||||
use db::kvp::KEY_VALUE_STORE;
|
use db::kvp::KEY_VALUE_STORE;
|
||||||
use editor::{
|
|
||||||
scroll::{Autoscroll, AutoscrollStrategy},
|
|
||||||
Editor, MultiBuffer, DEFAULT_MULTIBUFFER_CONTEXT,
|
|
||||||
};
|
|
||||||
use git::{
|
use git::{
|
||||||
diff::DiffHunk,
|
diff::DiffHunk,
|
||||||
repository::{GitFileStatus, RepoPath},
|
repository::{GitFileStatus, RepoPath},
|
||||||
|
@ -17,9 +13,8 @@ use gpui::{
|
||||||
ListHorizontalSizingBehavior, ListSizingBehavior, Model, Modifiers, ModifiersChangedEvent,
|
ListHorizontalSizingBehavior, ListSizingBehavior, Model, Modifiers, ModifiersChangedEvent,
|
||||||
MouseButton, ScrollStrategy, Stateful, Task, UniformListScrollHandle, View, WeakView,
|
MouseButton, ScrollStrategy, Stateful, Task, UniformListScrollHandle, View, WeakView,
|
||||||
};
|
};
|
||||||
use language::{Buffer, BufferRow, OffsetRangeExt};
|
|
||||||
use menu::{SelectNext, SelectPrev};
|
use menu::{SelectNext, SelectPrev};
|
||||||
use project::{EntryKind, Fs, Project, ProjectEntryId, ProjectPath, WorktreeId};
|
use project::{EntryKind, Fs, Project, ProjectEntryId, WorktreeId};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use settings::Settings as _;
|
use settings::Settings as _;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -40,7 +35,7 @@ use ui::{
|
||||||
use util::{ResultExt, TryFutureExt};
|
use util::{ResultExt, TryFutureExt};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
dock::{DockPosition, Panel, PanelEvent},
|
dock::{DockPosition, Panel, PanelEvent},
|
||||||
ItemHandle, Workspace,
|
Workspace,
|
||||||
};
|
};
|
||||||
use worktree::StatusEntry;
|
use worktree::StatusEntry;
|
||||||
|
|
||||||
|
@ -93,7 +88,7 @@ struct SerializedGitPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GitPanel {
|
pub struct GitPanel {
|
||||||
workspace: WeakView<Workspace>,
|
// workspace: WeakView<Workspace>,
|
||||||
current_modifiers: Modifiers,
|
current_modifiers: Modifiers,
|
||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
|
@ -111,8 +106,8 @@ pub struct GitPanel {
|
||||||
// not hidden by folding or such
|
// not hidden by folding or such
|
||||||
visible_entries: Vec<WorktreeEntries>,
|
visible_entries: Vec<WorktreeEntries>,
|
||||||
width: Option<Pixels>,
|
width: Option<Pixels>,
|
||||||
git_diff_editor: Option<View<Editor>>,
|
// git_diff_editor: Option<View<Editor>>,
|
||||||
git_diff_editor_updates: Task<()>,
|
// git_diff_editor_updates: Task<()>,
|
||||||
reveal_in_editor: Task<()>,
|
reveal_in_editor: Task<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +115,7 @@ pub struct GitPanel {
|
||||||
struct WorktreeEntries {
|
struct WorktreeEntries {
|
||||||
worktree_id: WorktreeId,
|
worktree_id: WorktreeId,
|
||||||
// TODO support multiple repositories per worktree
|
// TODO support multiple repositories per worktree
|
||||||
work_directory: worktree::WorkDirectory,
|
// work_directory: worktree::WorkDirectory,
|
||||||
visible_entries: Vec<GitPanelEntry>,
|
visible_entries: Vec<GitPanelEntry>,
|
||||||
paths: Rc<OnceCell<HashSet<RepoPath>>>,
|
paths: Rc<OnceCell<HashSet<RepoPath>>>,
|
||||||
}
|
}
|
||||||
|
@ -160,7 +155,7 @@ impl GitPanel {
|
||||||
|
|
||||||
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
|
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
|
||||||
let fs = workspace.app_state().fs.clone();
|
let fs = workspace.app_state().fs.clone();
|
||||||
let weak_workspace = workspace.weak_handle();
|
// let weak_workspace = workspace.weak_handle();
|
||||||
let project = workspace.project().clone();
|
let project = workspace.project().clone();
|
||||||
|
|
||||||
let git_panel = cx.new_view(|cx: &mut ViewContext<Self>| {
|
let git_panel = cx.new_view(|cx: &mut ViewContext<Self>| {
|
||||||
|
@ -171,9 +166,6 @@ impl GitPanel {
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
cx.subscribe(&project, |this, _, event, cx| match event {
|
cx.subscribe(&project, |this, _, event, cx| match event {
|
||||||
project::Event::GitRepositoryUpdated => {
|
|
||||||
this.update_visible_entries(None, None, cx);
|
|
||||||
}
|
|
||||||
project::Event::WorktreeRemoved(_id) => {
|
project::Event::WorktreeRemoved(_id) => {
|
||||||
// this.expanded_dir_ids.remove(id);
|
// this.expanded_dir_ids.remove(id);
|
||||||
this.update_visible_entries(None, None, cx);
|
this.update_visible_entries(None, None, cx);
|
||||||
|
@ -190,11 +182,11 @@ impl GitPanel {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
project::Event::Closed => {
|
project::Event::Closed => {
|
||||||
this.git_diff_editor_updates = Task::ready(());
|
// this.git_diff_editor_updates = Task::ready(());
|
||||||
this.reveal_in_editor = Task::ready(());
|
this.reveal_in_editor = Task::ready(());
|
||||||
// this.expanded_dir_ids.clear();
|
// this.expanded_dir_ids.clear();
|
||||||
this.visible_entries.clear();
|
this.visible_entries.clear();
|
||||||
this.git_diff_editor = None;
|
// this.git_diff_editor = None;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
})
|
})
|
||||||
|
@ -203,7 +195,7 @@ impl GitPanel {
|
||||||
let scroll_handle = UniformListScrollHandle::new();
|
let scroll_handle = UniformListScrollHandle::new();
|
||||||
|
|
||||||
let mut git_panel = Self {
|
let mut git_panel = Self {
|
||||||
workspace: weak_workspace,
|
// workspace: weak_workspace,
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
fs,
|
fs,
|
||||||
pending_serialization: Task::ready(None),
|
pending_serialization: Task::ready(None),
|
||||||
|
@ -216,8 +208,8 @@ impl GitPanel {
|
||||||
selected_item: None,
|
selected_item: None,
|
||||||
show_scrollbar: !Self::should_autohide_scrollbar(cx),
|
show_scrollbar: !Self::should_autohide_scrollbar(cx),
|
||||||
hide_scrollbar_task: None,
|
hide_scrollbar_task: None,
|
||||||
git_diff_editor: Some(diff_display_editor(cx)),
|
// git_diff_editor: Some(diff_display_editor(cx)),
|
||||||
git_diff_editor_updates: Task::ready(()),
|
// git_diff_editor_updates: Task::ready(()),
|
||||||
reveal_in_editor: Task::ready(()),
|
reveal_in_editor: Task::ready(()),
|
||||||
project,
|
project,
|
||||||
};
|
};
|
||||||
|
@ -527,6 +519,7 @@ impl GitPanel {
|
||||||
|
|
||||||
// TODO: Update expanded directory state
|
// TODO: Update expanded directory state
|
||||||
// TODO: Updates happen in the main loop, could be long for large workspaces
|
// TODO: Updates happen in the main loop, could be long for large workspaces
|
||||||
|
#[track_caller]
|
||||||
fn update_visible_entries(
|
fn update_visible_entries(
|
||||||
&mut self,
|
&mut self,
|
||||||
for_worktree: Option<WorktreeId>,
|
for_worktree: Option<WorktreeId>,
|
||||||
|
@ -562,10 +555,10 @@ impl GitPanel {
|
||||||
let mut visible_worktree_entries = Vec::new();
|
let mut visible_worktree_entries = Vec::new();
|
||||||
// Only use the first repository for now
|
// Only use the first repository for now
|
||||||
let repositories = snapshot.repositories().take(1);
|
let repositories = snapshot.repositories().take(1);
|
||||||
let mut work_directory = None;
|
// let mut work_directory = None;
|
||||||
for repository in repositories {
|
for repository in repositories {
|
||||||
visible_worktree_entries.extend(repository.status());
|
visible_worktree_entries.extend(repository.status());
|
||||||
work_directory = Some(worktree::WorkDirectory::clone(repository));
|
// work_directory = Some(worktree::WorkDirectory::clone(repository));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use the GitTraversal
|
// TODO use the GitTraversal
|
||||||
|
@ -581,7 +574,7 @@ impl GitPanel {
|
||||||
if !visible_worktree_entries.is_empty() {
|
if !visible_worktree_entries.is_empty() {
|
||||||
self.visible_entries.push(WorktreeEntries {
|
self.visible_entries.push(WorktreeEntries {
|
||||||
worktree_id,
|
worktree_id,
|
||||||
work_directory: work_directory.unwrap(),
|
// work_directory: work_directory.unwrap(),
|
||||||
visible_entries: visible_worktree_entries
|
visible_entries: visible_worktree_entries
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|entry| GitPanelEntry {
|
.map(|entry| GitPanelEntry {
|
||||||
|
@ -615,166 +608,166 @@ impl GitPanel {
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let project = self.project.downgrade();
|
// let project = self.project.downgrade();
|
||||||
self.git_diff_editor_updates = cx.spawn(|git_panel, mut cx| async move {
|
// self.git_diff_editor_updates = cx.spawn(|git_panel, mut cx| async move {
|
||||||
cx.background_executor()
|
// cx.background_executor()
|
||||||
.timer(UPDATE_DEBOUNCE)
|
// .timer(UPDATE_DEBOUNCE)
|
||||||
.await;
|
// .await;
|
||||||
let Some(project_buffers) = git_panel
|
// let Some(project_buffers) = git_panel
|
||||||
.update(&mut cx, |git_panel, cx| {
|
// .update(&mut cx, |git_panel, cx| {
|
||||||
futures::future::join_all(git_panel.visible_entries.iter_mut().flat_map(
|
// futures::future::join_all(git_panel.visible_entries.iter_mut().flat_map(
|
||||||
|worktree_entries| {
|
// |worktree_entries| {
|
||||||
worktree_entries
|
// worktree_entries
|
||||||
.visible_entries
|
// .visible_entries
|
||||||
.iter()
|
// .iter()
|
||||||
.filter_map(|entry| {
|
// .filter_map(|entry| {
|
||||||
let git_status = entry.status;
|
// let git_status = entry.status;
|
||||||
let entry_hunks = entry.hunks.clone();
|
// let entry_hunks = entry.hunks.clone();
|
||||||
let (entry_path, unstaged_changes_task) =
|
// let (entry_path, unstaged_changes_task) =
|
||||||
project.update(cx, |project, cx| {
|
// project.update(cx, |project, cx| {
|
||||||
let entry_path = ProjectPath {
|
// let entry_path = ProjectPath {
|
||||||
worktree_id: worktree_entries.worktree_id,
|
// worktree_id: worktree_entries.worktree_id,
|
||||||
path: worktree_entries.work_directory.unrelativize(&entry.repo_path)?,
|
// path: worktree_entries.work_directory.unrelativize(&entry.repo_path)?,
|
||||||
};
|
// };
|
||||||
let open_task =
|
// let open_task =
|
||||||
project.open_path(entry_path.clone(), cx);
|
// project.open_path(entry_path.clone(), cx);
|
||||||
let unstaged_changes_task =
|
// let unstaged_changes_task =
|
||||||
cx.spawn(|project, mut cx| async move {
|
// cx.spawn(|project, mut cx| async move {
|
||||||
let (_, opened_model) = open_task
|
// let (_, opened_model) = open_task
|
||||||
.await
|
// .await
|
||||||
.context("opening buffer")?;
|
// .context("opening buffer")?;
|
||||||
let buffer = opened_model
|
// let buffer = opened_model
|
||||||
.downcast::<Buffer>()
|
// .downcast::<Buffer>()
|
||||||
.map_err(|_| {
|
// .map_err(|_| {
|
||||||
anyhow::anyhow!(
|
// anyhow::anyhow!(
|
||||||
"accessing buffer for entry"
|
// "accessing buffer for entry"
|
||||||
)
|
// )
|
||||||
})?;
|
// })?;
|
||||||
// TODO added files have noop changes and those are not expanded properly in the multi buffer
|
// // TODO added files have noop changes and those are not expanded properly in the multi buffer
|
||||||
let unstaged_changes = project
|
// let unstaged_changes = project
|
||||||
.update(&mut cx, |project, cx| {
|
// .update(&mut cx, |project, cx| {
|
||||||
project.open_unstaged_changes(
|
// project.open_unstaged_changes(
|
||||||
buffer.clone(),
|
// buffer.clone(),
|
||||||
cx,
|
// cx,
|
||||||
)
|
// )
|
||||||
})?
|
// })?
|
||||||
.await
|
// .await
|
||||||
.context("opening unstaged changes")?;
|
// .context("opening unstaged changes")?;
|
||||||
|
|
||||||
let hunks = cx.update(|cx| {
|
// let hunks = cx.update(|cx| {
|
||||||
entry_hunks
|
// entry_hunks
|
||||||
.get_or_init(|| {
|
// .get_or_init(|| {
|
||||||
match git_status {
|
// match git_status {
|
||||||
GitFileStatus::Added => {
|
// GitFileStatus::Added => {
|
||||||
let buffer_snapshot = buffer.read(cx).snapshot();
|
// let buffer_snapshot = buffer.read(cx).snapshot();
|
||||||
let entire_buffer_range =
|
// let entire_buffer_range =
|
||||||
buffer_snapshot.anchor_after(0)
|
// buffer_snapshot.anchor_after(0)
|
||||||
..buffer_snapshot
|
// ..buffer_snapshot
|
||||||
.anchor_before(
|
// .anchor_before(
|
||||||
buffer_snapshot.len(),
|
// buffer_snapshot.len(),
|
||||||
);
|
// );
|
||||||
let entire_buffer_point_range =
|
// let entire_buffer_point_range =
|
||||||
entire_buffer_range
|
// entire_buffer_range
|
||||||
.clone()
|
// .clone()
|
||||||
.to_point(&buffer_snapshot);
|
// .to_point(&buffer_snapshot);
|
||||||
|
|
||||||
vec![DiffHunk {
|
// vec![DiffHunk {
|
||||||
row_range: entire_buffer_point_range
|
// row_range: entire_buffer_point_range
|
||||||
.start
|
// .start
|
||||||
.row
|
// .row
|
||||||
..entire_buffer_point_range
|
// ..entire_buffer_point_range
|
||||||
.end
|
// .end
|
||||||
.row,
|
// .row,
|
||||||
buffer_range: entire_buffer_range,
|
// buffer_range: entire_buffer_range,
|
||||||
diff_base_byte_range: 0..0,
|
// diff_base_byte_range: 0..0,
|
||||||
}]
|
// }]
|
||||||
}
|
// }
|
||||||
GitFileStatus::Modified => {
|
// GitFileStatus::Modified => {
|
||||||
let buffer_snapshot =
|
// let buffer_snapshot =
|
||||||
buffer.read(cx).snapshot();
|
// buffer.read(cx).snapshot();
|
||||||
unstaged_changes.read(cx)
|
// unstaged_changes.read(cx)
|
||||||
.diff_to_buffer
|
// .diff_to_buffer
|
||||||
.hunks_in_row_range(
|
// .hunks_in_row_range(
|
||||||
0..BufferRow::MAX,
|
// 0..BufferRow::MAX,
|
||||||
&buffer_snapshot,
|
// &buffer_snapshot,
|
||||||
)
|
// )
|
||||||
.collect()
|
// .collect()
|
||||||
}
|
// }
|
||||||
// TODO support these
|
// // TODO support these
|
||||||
GitFileStatus::Conflict | GitFileStatus::Deleted | GitFileStatus::Untracked => Vec::new(),
|
// GitFileStatus::Conflict | GitFileStatus::Deleted | GitFileStatus::Untracked => Vec::new(),
|
||||||
}
|
// }
|
||||||
}).clone()
|
// }).clone()
|
||||||
})?;
|
// })?;
|
||||||
|
|
||||||
anyhow::Ok((buffer, unstaged_changes, hunks))
|
// anyhow::Ok((buffer, unstaged_changes, hunks))
|
||||||
});
|
// });
|
||||||
Some((entry_path, unstaged_changes_task))
|
// Some((entry_path, unstaged_changes_task))
|
||||||
}).ok()??;
|
// }).ok()??;
|
||||||
Some((entry_path, unstaged_changes_task))
|
// Some((entry_path, unstaged_changes_task))
|
||||||
})
|
// })
|
||||||
.map(|(entry_path, open_task)| async move {
|
// .map(|(entry_path, open_task)| async move {
|
||||||
(entry_path, open_task.await)
|
// (entry_path, open_task.await)
|
||||||
})
|
// })
|
||||||
.collect::<Vec<_>>()
|
// .collect::<Vec<_>>()
|
||||||
},
|
// },
|
||||||
))
|
// ))
|
||||||
})
|
// })
|
||||||
.ok()
|
// .ok()
|
||||||
else {
|
// else {
|
||||||
return;
|
// return;
|
||||||
};
|
// };
|
||||||
|
|
||||||
let project_buffers = project_buffers.await;
|
// let project_buffers = project_buffers.await;
|
||||||
if project_buffers.is_empty() {
|
// if project_buffers.is_empty() {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
let mut change_sets = Vec::with_capacity(project_buffers.len());
|
// let mut change_sets = Vec::with_capacity(project_buffers.len());
|
||||||
if let Some(buffer_update_task) = git_panel
|
// if let Some(buffer_update_task) = git_panel
|
||||||
.update(&mut cx, |git_panel, cx| {
|
// .update(&mut cx, |git_panel, cx| {
|
||||||
let editor = git_panel.git_diff_editor.clone()?;
|
// let editor = git_panel.git_diff_editor.clone()?;
|
||||||
let multi_buffer = editor.read(cx).buffer().clone();
|
// let multi_buffer = editor.read(cx).buffer().clone();
|
||||||
let mut buffers_with_ranges = Vec::with_capacity(project_buffers.len());
|
// let mut buffers_with_ranges = Vec::with_capacity(project_buffers.len());
|
||||||
for (buffer_path, open_result) in project_buffers {
|
// for (buffer_path, open_result) in project_buffers {
|
||||||
if let Some((buffer, unstaged_changes, diff_hunks)) = open_result
|
// if let Some((buffer, unstaged_changes, diff_hunks)) = open_result
|
||||||
.with_context(|| format!("opening buffer {buffer_path:?}"))
|
// .with_context(|| format!("opening buffer {buffer_path:?}"))
|
||||||
.log_err()
|
// .log_err()
|
||||||
{
|
// {
|
||||||
change_sets.push(unstaged_changes);
|
// change_sets.push(unstaged_changes);
|
||||||
buffers_with_ranges.push((
|
// buffers_with_ranges.push((
|
||||||
buffer,
|
// buffer,
|
||||||
diff_hunks
|
// diff_hunks
|
||||||
.into_iter()
|
// .into_iter()
|
||||||
.map(|hunk| hunk.buffer_range)
|
// .map(|hunk| hunk.buffer_range)
|
||||||
.collect(),
|
// .collect(),
|
||||||
));
|
// ));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
Some(multi_buffer.update(cx, |multi_buffer, cx| {
|
// Some(multi_buffer.update(cx, |multi_buffer, cx| {
|
||||||
multi_buffer.clear(cx);
|
// multi_buffer.clear(cx);
|
||||||
multi_buffer.push_multiple_excerpts_with_context_lines(
|
// multi_buffer.push_multiple_excerpts_with_context_lines(
|
||||||
buffers_with_ranges,
|
// buffers_with_ranges,
|
||||||
DEFAULT_MULTIBUFFER_CONTEXT,
|
// DEFAULT_MULTIBUFFER_CONTEXT,
|
||||||
cx,
|
// cx,
|
||||||
)
|
// )
|
||||||
}))
|
// }))
|
||||||
})
|
// })
|
||||||
.ok().flatten()
|
// .ok().flatten()
|
||||||
{
|
// {
|
||||||
buffer_update_task.await;
|
// buffer_update_task.await;
|
||||||
git_panel
|
// git_panel
|
||||||
.update(&mut cx, |git_panel, cx| {
|
// .update(&mut cx, |git_panel, cx| {
|
||||||
if let Some(diff_editor) = git_panel.git_diff_editor.as_ref() {
|
// if let Some(diff_editor) = git_panel.git_diff_editor.as_ref() {
|
||||||
diff_editor.update(cx, |editor, cx| {
|
// diff_editor.update(cx, |editor, cx| {
|
||||||
for change_set in change_sets {
|
// for change_set in change_sets {
|
||||||
editor.add_change_set(change_set, cx);
|
// editor.add_change_set(change_set, cx);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
.ok();
|
// .ok();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
@ -1058,94 +1051,94 @@ impl GitPanel {
|
||||||
|
|
||||||
fn reveal_entry_in_git_editor(
|
fn reveal_entry_in_git_editor(
|
||||||
&mut self,
|
&mut self,
|
||||||
hunks: Rc<OnceCell<Vec<DiffHunk>>>,
|
_hunks: Rc<OnceCell<Vec<DiffHunk>>>,
|
||||||
change_focus: bool,
|
_change_focus: bool,
|
||||||
debounce: Option<Duration>,
|
_debounce: Option<Duration>,
|
||||||
cx: &mut ViewContext<Self>,
|
_cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let workspace = self.workspace.clone();
|
// let workspace = self.workspace.clone();
|
||||||
let Some(diff_editor) = self.git_diff_editor.clone() else {
|
// let Some(diff_editor) = self.git_diff_editor.clone() else {
|
||||||
return;
|
// return;
|
||||||
};
|
// };
|
||||||
self.reveal_in_editor = cx.spawn(|_, mut cx| async move {
|
// self.reveal_in_editor = cx.spawn(|_, mut cx| async move {
|
||||||
if let Some(debounce) = debounce {
|
// if let Some(debounce) = debounce {
|
||||||
cx.background_executor().timer(debounce).await;
|
// cx.background_executor().timer(debounce).await;
|
||||||
}
|
// }
|
||||||
|
|
||||||
let Some(editor) = workspace
|
// let Some(editor) = workspace
|
||||||
.update(&mut cx, |workspace, cx| {
|
// .update(&mut cx, |workspace, cx| {
|
||||||
let git_diff_editor = workspace
|
// let git_diff_editor = workspace
|
||||||
.items_of_type::<Editor>(cx)
|
// .items_of_type::<Editor>(cx)
|
||||||
.find(|editor| &diff_editor == editor);
|
// .find(|editor| &diff_editor == editor);
|
||||||
match git_diff_editor {
|
// match git_diff_editor {
|
||||||
Some(existing_editor) => {
|
// Some(existing_editor) => {
|
||||||
workspace.activate_item(&existing_editor, true, change_focus, cx);
|
// workspace.activate_item(&existing_editor, true, change_focus, cx);
|
||||||
existing_editor
|
// existing_editor
|
||||||
}
|
// }
|
||||||
None => {
|
// None => {
|
||||||
workspace.active_pane().update(cx, |pane, cx| {
|
// workspace.active_pane().update(cx, |pane, cx| {
|
||||||
pane.add_item(
|
// pane.add_item(
|
||||||
diff_editor.boxed_clone(),
|
// ` diff_editor.boxed_clone(),
|
||||||
true,
|
// true,
|
||||||
change_focus,
|
// change_focus,
|
||||||
None,
|
// None,
|
||||||
cx,
|
// cx,
|
||||||
)
|
// )
|
||||||
});
|
// });
|
||||||
diff_editor.clone()
|
// diff_editor.clone()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
.ok()
|
// .ok()
|
||||||
else {
|
// else {
|
||||||
return;
|
// return;
|
||||||
};
|
// };
|
||||||
|
|
||||||
if let Some(first_hunk) = hunks.get().and_then(|hunks| hunks.first()) {
|
// if let Some(first_hunk) = hunks.get().and_then(|hunks| hunks.first()) {
|
||||||
let hunk_buffer_range = &first_hunk.buffer_range;
|
// let hunk_buffer_range = &first_hunk.buffer_range;
|
||||||
if let Some(buffer_id) = hunk_buffer_range
|
// if let Some(buffer_id) = hunk_buffer_range
|
||||||
.start
|
// .start
|
||||||
.buffer_id
|
// .buffer_id
|
||||||
.or_else(|| first_hunk.buffer_range.end.buffer_id)
|
// .or_else(|| first_hunk.buffer_range.end.buffer_id)
|
||||||
{
|
// {
|
||||||
editor
|
// editor
|
||||||
.update(&mut cx, |editor, cx| {
|
// .update(&mut cx, |editor, cx| {
|
||||||
let multi_buffer = editor.buffer().read(cx);
|
// let multi_buffer = editor.buffer().read(cx);
|
||||||
let buffer = multi_buffer.buffer(buffer_id)?;
|
// let buffer = multi_buffer.buffer(buffer_id)?;
|
||||||
let buffer_snapshot = buffer.read(cx).snapshot();
|
// let buffer_snapshot = buffer.read(cx).snapshot();
|
||||||
let (excerpt_id, _) = multi_buffer
|
// let (excerpt_id, _) = multi_buffer
|
||||||
.excerpts_for_buffer(&buffer, cx)
|
// .excerpts_for_buffer(&buffer, cx)
|
||||||
.into_iter()
|
// .into_iter()
|
||||||
.find(|(_, excerpt)| {
|
// .find(|(_, excerpt)| {
|
||||||
hunk_buffer_range
|
// hunk_buffer_range
|
||||||
.start
|
// .start
|
||||||
.cmp(&excerpt.context.start, &buffer_snapshot)
|
// .cmp(&excerpt.context.start, &buffer_snapshot)
|
||||||
.is_ge()
|
// .is_ge()
|
||||||
&& hunk_buffer_range
|
// && hunk_buffer_range
|
||||||
.end
|
// .end
|
||||||
.cmp(&excerpt.context.end, &buffer_snapshot)
|
// .cmp(&excerpt.context.end, &buffer_snapshot)
|
||||||
.is_le()
|
// .is_le()
|
||||||
})?;
|
// })?;
|
||||||
let multi_buffer_hunk_start = multi_buffer
|
// let multi_buffer_hunk_start = multi_buffer
|
||||||
.snapshot(cx)
|
// .snapshot(cx)
|
||||||
.anchor_in_excerpt(excerpt_id, hunk_buffer_range.start)?;
|
// .anchor_in_excerpt(excerpt_id, hunk_buffer_range.start)?;
|
||||||
editor.change_selections(
|
// editor.change_selections(
|
||||||
Some(Autoscroll::Strategy(AutoscrollStrategy::Center)),
|
// Some(Autoscroll::Strategy(AutoscrollStrategy::Center)),
|
||||||
cx,
|
// cx,
|
||||||
|s| {
|
// |s| {
|
||||||
s.select_ranges(Some(
|
// s.select_ranges(Some(
|
||||||
multi_buffer_hunk_start..multi_buffer_hunk_start,
|
// multi_buffer_hunk_start..multi_buffer_hunk_start,
|
||||||
))
|
// ))
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
cx.notify();
|
// cx.notify();
|
||||||
Some(())
|
// Some(())
|
||||||
})
|
// })
|
||||||
.ok()
|
// .ok()
|
||||||
.flatten();
|
// .flatten();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1260,13 +1253,13 @@ impl Panel for GitPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn diff_display_editor(cx: &mut WindowContext) -> View<Editor> {
|
// fn diff_display_editor(cx: &mut WindowContext) -> View<Editor> {
|
||||||
cx.new_view(|cx| {
|
// cx.new_view(|cx| {
|
||||||
let multi_buffer = cx.new_model(|_| {
|
// let multi_buffer = cx.new_model(|_| {
|
||||||
MultiBuffer::new(language::Capability::ReadWrite).with_title("Project diff".to_string())
|
// MultiBuffer::new(language::Capability::ReadWrite).with_title("Project diff".to_string())
|
||||||
});
|
// });
|
||||||
let mut editor = Editor::for_multibuffer(multi_buffer, None, true, cx);
|
// let mut editor = Editor::for_multibuffer(multi_buffer, None, true, cx);
|
||||||
editor.set_expand_all_diff_hunks();
|
// editor.set_expand_all_diff_hunks();
|
||||||
editor
|
// editor
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
|
|
|
@ -3108,7 +3108,6 @@ impl LspStore {
|
||||||
WorktreeStoreEvent::WorktreeUpdateSent(worktree) => {
|
WorktreeStoreEvent::WorktreeUpdateSent(worktree) => {
|
||||||
worktree.update(cx, |worktree, _cx| self.send_diagnostic_summaries(worktree));
|
worktree.update(cx, |worktree, _cx| self.send_diagnostic_summaries(worktree));
|
||||||
}
|
}
|
||||||
WorktreeStoreEvent::GitRepositoryUpdated => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,6 @@ pub enum Event {
|
||||||
ActivateProjectPanel,
|
ActivateProjectPanel,
|
||||||
WorktreeAdded(WorktreeId),
|
WorktreeAdded(WorktreeId),
|
||||||
WorktreeOrderChanged,
|
WorktreeOrderChanged,
|
||||||
GitRepositoryUpdated,
|
|
||||||
WorktreeRemoved(WorktreeId),
|
WorktreeRemoved(WorktreeId),
|
||||||
WorktreeUpdatedEntries(WorktreeId, UpdatedEntriesSet),
|
WorktreeUpdatedEntries(WorktreeId, UpdatedEntriesSet),
|
||||||
WorktreeUpdatedGitRepositories(WorktreeId),
|
WorktreeUpdatedGitRepositories(WorktreeId),
|
||||||
|
@ -2307,7 +2306,6 @@ impl Project {
|
||||||
}
|
}
|
||||||
WorktreeStoreEvent::WorktreeOrderChanged => cx.emit(Event::WorktreeOrderChanged),
|
WorktreeStoreEvent::WorktreeOrderChanged => cx.emit(Event::WorktreeOrderChanged),
|
||||||
WorktreeStoreEvent::WorktreeUpdateSent(_) => {}
|
WorktreeStoreEvent::WorktreeUpdateSent(_) => {}
|
||||||
WorktreeStoreEvent::GitRepositoryUpdated => cx.emit(Event::GitRepositoryUpdated),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ pub enum WorktreeStoreEvent {
|
||||||
WorktreeReleased(EntityId, WorktreeId),
|
WorktreeReleased(EntityId, WorktreeId),
|
||||||
WorktreeOrderChanged,
|
WorktreeOrderChanged,
|
||||||
WorktreeUpdateSent(Model<Worktree>),
|
WorktreeUpdateSent(Model<Worktree>),
|
||||||
GitRepositoryUpdated,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter<WorktreeStoreEvent> for WorktreeStore {}
|
impl EventEmitter<WorktreeStoreEvent> for WorktreeStore {}
|
||||||
|
@ -376,17 +375,6 @@ impl WorktreeStore {
|
||||||
this.send_project_updates(cx);
|
this.send_project_updates(cx);
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
cx.subscribe(
|
|
||||||
worktree,
|
|
||||||
|_this, _, event: &worktree::Event, cx| match event {
|
|
||||||
worktree::Event::UpdatedGitRepositories(_) => {
|
|
||||||
cx.emit(WorktreeStoreEvent::GitRepositoryUpdated);
|
|
||||||
}
|
|
||||||
worktree::Event::DeletedEntry(_) | worktree::Event::UpdatedEntries(_) => {}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut ModelContext<Self>) {
|
pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut ModelContext<Self>) {
|
||||||
|
|
|
@ -311,7 +311,7 @@ impl ProjectPanel {
|
||||||
this.update_visible_entries(None, cx);
|
this.update_visible_entries(None, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
project::Event::GitRepositoryUpdated
|
project::Event::WorktreeUpdatedGitRepositories(_)
|
||||||
| project::Event::WorktreeUpdatedEntries(_, _)
|
| project::Event::WorktreeUpdatedEntries(_, _)
|
||||||
| project::Event::WorktreeAdded(_)
|
| project::Event::WorktreeAdded(_)
|
||||||
| project::Event::WorktreeOrderChanged => {
|
| project::Event::WorktreeOrderChanged => {
|
||||||
|
|
Loading…
Reference in a new issue