Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -4,7 +4,7 @@ use git::{
|
|||
blame::{Blame, BlameEntry},
|
||||
parse_git_remote_url, GitHostingProvider, GitHostingProviderRegistry, Oid, PullRequest,
|
||||
};
|
||||
use gpui::{AppContext, Model, ModelContext, Subscription, Task};
|
||||
use gpui::{App, Context, Entity, Subscription, Task};
|
||||
use http_client::HttpClient;
|
||||
use language::{markdown, Bias, Buffer, BufferSnapshot, Edit, LanguageRegistry, ParsedMarkdown};
|
||||
use multi_buffer::RowInfo;
|
||||
|
@ -96,8 +96,8 @@ pub struct CommitDetails {
|
|||
}
|
||||
|
||||
pub struct GitBlame {
|
||||
project: Model<Project>,
|
||||
buffer: Model<Buffer>,
|
||||
project: Entity<Project>,
|
||||
buffer: Entity<Buffer>,
|
||||
entries: SumTree<GitBlameEntry>,
|
||||
commit_details: HashMap<Oid, CommitDetails>,
|
||||
buffer_snapshot: BufferSnapshot,
|
||||
|
@ -113,11 +113,11 @@ pub struct GitBlame {
|
|||
|
||||
impl GitBlame {
|
||||
pub fn new(
|
||||
buffer: Model<Buffer>,
|
||||
project: Model<Project>,
|
||||
buffer: Entity<Buffer>,
|
||||
project: Entity<Project>,
|
||||
user_triggered: bool,
|
||||
focused: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let entries = SumTree::from_item(
|
||||
GitBlameEntry {
|
||||
|
@ -194,7 +194,7 @@ impl GitBlame {
|
|||
pub fn blame_for_rows<'a>(
|
||||
&'a mut self,
|
||||
rows: &'a [RowInfo],
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> impl 'a + Iterator<Item = Option<BlameEntry>> {
|
||||
self.sync(cx);
|
||||
|
||||
|
@ -206,7 +206,7 @@ impl GitBlame {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn max_author_length(&mut self, cx: &AppContext) -> usize {
|
||||
pub fn max_author_length(&mut self, cx: &App) -> usize {
|
||||
self.sync(cx);
|
||||
|
||||
let mut max_author_length = 0;
|
||||
|
@ -227,11 +227,11 @@ impl GitBlame {
|
|||
max_author_length
|
||||
}
|
||||
|
||||
pub fn blur(&mut self, _: &mut ModelContext<Self>) {
|
||||
pub fn blur(&mut self, _: &mut Context<Self>) {
|
||||
self.focused = false;
|
||||
}
|
||||
|
||||
pub fn focus(&mut self, cx: &mut ModelContext<Self>) {
|
||||
pub fn focus(&mut self, cx: &mut Context<Self>) {
|
||||
self.focused = true;
|
||||
if self.changed_while_blurred {
|
||||
self.changed_while_blurred = false;
|
||||
|
@ -239,7 +239,7 @@ impl GitBlame {
|
|||
}
|
||||
}
|
||||
|
||||
fn sync(&mut self, cx: &AppContext) {
|
||||
fn sync(&mut self, cx: &App) {
|
||||
let edits = self.buffer_edits.consume();
|
||||
let new_snapshot = self.buffer.read(cx).snapshot();
|
||||
|
||||
|
@ -342,7 +342,7 @@ impl GitBlame {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn check_invariants(&mut self, cx: &mut ModelContext<Self>) {
|
||||
fn check_invariants(&mut self, cx: &mut Context<Self>) {
|
||||
self.sync(cx);
|
||||
assert_eq!(
|
||||
self.entries.summary().rows,
|
||||
|
@ -350,7 +350,7 @@ impl GitBlame {
|
|||
);
|
||||
}
|
||||
|
||||
fn generate(&mut self, cx: &mut ModelContext<Self>) {
|
||||
fn generate(&mut self, cx: &mut Context<Self>) {
|
||||
if !self.focused {
|
||||
self.changed_while_blurred = true;
|
||||
return;
|
||||
|
@ -422,7 +422,7 @@ impl GitBlame {
|
|||
});
|
||||
}
|
||||
|
||||
fn regenerate_on_edit(&mut self, cx: &mut ModelContext<Self>) {
|
||||
fn regenerate_on_edit(&mut self, cx: &mut Context<Self>) {
|
||||
self.regenerate_on_edit_task = cx.spawn(|this, mut cx| async move {
|
||||
cx.background_executor()
|
||||
.timer(REGENERATE_ON_EDIT_DEBOUNCE_INTERVAL)
|
||||
|
@ -552,7 +552,7 @@ async fn parse_markdown(text: &str, language_registry: &Arc<LanguageRegistry>) -
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use gpui::Context;
|
||||
use gpui::{AppContext as _, Context};
|
||||
use language::{Point, Rope};
|
||||
use project::FakeFs;
|
||||
use rand::prelude::*;
|
||||
|
@ -578,7 +578,7 @@ mod tests {
|
|||
blame: &mut GitBlame,
|
||||
rows: Range<u32>,
|
||||
expected: Vec<Option<BlameEntry>>,
|
||||
cx: &mut ModelContext<GitBlame>,
|
||||
cx: &mut Context<GitBlame>,
|
||||
) {
|
||||
assert_eq!(
|
||||
blame
|
||||
|
@ -640,8 +640,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let blame =
|
||||
cx.new_model(|cx| GitBlame::new(buffer.clone(), project.clone(), true, true, cx));
|
||||
let blame = cx.new(|cx| GitBlame::new(buffer.clone(), project.clone(), true, true, cx));
|
||||
|
||||
let event = project.next_event(cx).await;
|
||||
assert_eq!(
|
||||
|
@ -720,7 +719,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let git_blame = cx.new_model(|cx| GitBlame::new(buffer.clone(), project, false, true, cx));
|
||||
let git_blame = cx.new(|cx| GitBlame::new(buffer.clone(), project, false, true, cx));
|
||||
|
||||
cx.executor().run_until_parked();
|
||||
|
||||
|
@ -826,7 +825,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let git_blame = cx.new_model(|cx| GitBlame::new(buffer.clone(), project, false, true, cx));
|
||||
let git_blame = cx.new(|cx| GitBlame::new(buffer.clone(), project, false, true, cx));
|
||||
|
||||
cx.executor().run_until_parked();
|
||||
|
||||
|
@ -975,7 +974,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let git_blame = cx.new_model(|cx| GitBlame::new(buffer.clone(), project, false, true, cx));
|
||||
let git_blame = cx.new(|cx| GitBlame::new(buffer.clone(), project, false, true, cx));
|
||||
cx.executor().run_until_parked();
|
||||
git_blame.update(cx, |blame, cx| blame.check_invariants(cx));
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ use collections::{BTreeMap, HashMap};
|
|||
use feature_flags::FeatureFlagAppExt;
|
||||
use git::diff::{BufferDiff, DiffHunk};
|
||||
use gpui::{
|
||||
actions, AnyElement, AnyView, AppContext, EventEmitter, FocusHandle, FocusableView,
|
||||
InteractiveElement, Model, Render, Subscription, Task, View, WeakView,
|
||||
actions, AnyElement, AnyView, App, Entity, EventEmitter, FocusHandle, Focusable,
|
||||
InteractiveElement, Render, Subscription, Task, WeakEntity,
|
||||
};
|
||||
use language::{Buffer, BufferRow};
|
||||
use multi_buffer::{ExcerptId, ExcerptRange, ExpandExcerptDirection, MultiBuffer};
|
||||
|
@ -30,8 +30,8 @@ use crate::{Editor, EditorEvent, DEFAULT_MULTIBUFFER_CONTEXT};
|
|||
|
||||
actions!(project_diff, [Deploy]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.observe_new_views(ProjectDiffEditor::register).detach();
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.observe_new(ProjectDiffEditor::register).detach();
|
||||
}
|
||||
|
||||
const UPDATE_DEBOUNCE: Duration = Duration::from_millis(50);
|
||||
|
@ -39,11 +39,11 @@ const UPDATE_DEBOUNCE: Duration = Duration::from_millis(50);
|
|||
struct ProjectDiffEditor {
|
||||
buffer_changes: BTreeMap<WorktreeId, HashMap<ProjectEntryId, Changes>>,
|
||||
entry_order: HashMap<WorktreeId, Vec<(ProjectPath, ProjectEntryId)>>,
|
||||
excerpts: Model<MultiBuffer>,
|
||||
editor: View<Editor>,
|
||||
excerpts: Entity<MultiBuffer>,
|
||||
editor: Entity<Editor>,
|
||||
|
||||
project: Model<Project>,
|
||||
workspace: WeakView<Workspace>,
|
||||
project: Entity<Project>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
focus_handle: FocusHandle,
|
||||
worktree_rescans: HashMap<WorktreeId, Task<()>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
|
@ -51,40 +51,50 @@ struct ProjectDiffEditor {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct Changes {
|
||||
buffer: Model<Buffer>,
|
||||
buffer: Entity<Buffer>,
|
||||
hunks: Vec<DiffHunk>,
|
||||
}
|
||||
|
||||
impl ProjectDiffEditor {
|
||||
fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
|
||||
fn register(
|
||||
workspace: &mut Workspace,
|
||||
_window: Option<&mut Window>,
|
||||
_: &mut Context<Workspace>,
|
||||
) {
|
||||
workspace.register_action(Self::deploy);
|
||||
}
|
||||
|
||||
fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
|
||||
fn deploy(
|
||||
workspace: &mut Workspace,
|
||||
_: &Deploy,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) {
|
||||
if !cx.is_staff() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(existing) = workspace.item_of_type::<Self>(cx) {
|
||||
workspace.activate_item(&existing, true, true, cx);
|
||||
workspace.activate_item(&existing, true, true, window, cx);
|
||||
} else {
|
||||
let workspace_handle = cx.view().downgrade();
|
||||
let workspace_handle = cx.model().downgrade();
|
||||
let project_diff =
|
||||
cx.new_view(|cx| Self::new(workspace.project().clone(), workspace_handle, cx));
|
||||
workspace.add_item_to_active_pane(Box::new(project_diff), None, true, cx);
|
||||
cx.new(|cx| Self::new(workspace.project().clone(), workspace_handle, window, cx));
|
||||
workspace.add_item_to_active_pane(Box::new(project_diff), None, true, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn new(
|
||||
project: Model<Project>,
|
||||
workspace: WeakView<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
project: Entity<Project>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
// TODO diff change subscriptions. For that, needed:
|
||||
// * `-20/+50` stats retrieval: some background process that reacts on file changes
|
||||
let focus_handle = cx.focus_handle();
|
||||
let changed_entries_subscription =
|
||||
cx.subscribe(&project, |project_diff_editor, _, e, cx| {
|
||||
cx.subscribe_in(&project, window, |project_diff_editor, _, e, window, cx| {
|
||||
let mut worktree_to_rescan = None;
|
||||
match e {
|
||||
project::Event::WorktreeAdded(id) => {
|
||||
|
@ -137,15 +147,15 @@ impl ProjectDiffEditor {
|
|||
}
|
||||
|
||||
if let Some(worktree_to_rescan) = worktree_to_rescan {
|
||||
project_diff_editor.schedule_worktree_rescan(worktree_to_rescan, cx);
|
||||
project_diff_editor.schedule_worktree_rescan(worktree_to_rescan, window, cx);
|
||||
}
|
||||
});
|
||||
|
||||
let excerpts = cx.new_model(|cx| MultiBuffer::new(project.read(cx).capability()));
|
||||
let excerpts = cx.new(|cx| MultiBuffer::new(project.read(cx).capability()));
|
||||
|
||||
let editor = cx.new_view(|cx| {
|
||||
let editor = cx.new(|cx| {
|
||||
let mut diff_display_editor =
|
||||
Editor::for_multibuffer(excerpts.clone(), Some(project.clone()), true, cx);
|
||||
Editor::for_multibuffer(excerpts.clone(), Some(project.clone()), true, window, cx);
|
||||
diff_display_editor.set_expand_all_diff_hunks(cx);
|
||||
diff_display_editor
|
||||
});
|
||||
|
@ -161,16 +171,16 @@ impl ProjectDiffEditor {
|
|||
excerpts,
|
||||
_subscriptions: vec![changed_entries_subscription],
|
||||
};
|
||||
new_self.schedule_rescan_all(cx);
|
||||
new_self.schedule_rescan_all(window, cx);
|
||||
new_self
|
||||
}
|
||||
|
||||
fn schedule_rescan_all(&mut self, cx: &mut ViewContext<Self>) {
|
||||
fn schedule_rescan_all(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let mut current_worktrees = HashSet::<WorktreeId>::default();
|
||||
for worktree in self.project.read(cx).worktrees(cx).collect::<Vec<_>>() {
|
||||
let worktree_id = worktree.read(cx).id();
|
||||
current_worktrees.insert(worktree_id);
|
||||
self.schedule_worktree_rescan(worktree_id, cx);
|
||||
self.schedule_worktree_rescan(worktree_id, window, cx);
|
||||
}
|
||||
|
||||
self.worktree_rescans
|
||||
|
@ -181,11 +191,16 @@ impl ProjectDiffEditor {
|
|||
.retain(|worktree_id, _| current_worktrees.contains(worktree_id));
|
||||
}
|
||||
|
||||
fn schedule_worktree_rescan(&mut self, id: WorktreeId, cx: &mut ViewContext<Self>) {
|
||||
fn schedule_worktree_rescan(
|
||||
&mut self,
|
||||
id: WorktreeId,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let project = self.project.clone();
|
||||
self.worktree_rescans.insert(
|
||||
id,
|
||||
cx.spawn(|project_diff_editor, mut cx| async move {
|
||||
cx.spawn_in(window, |project_diff_editor, mut cx| async move {
|
||||
cx.background_executor().timer(UPDATE_DEBOUNCE).await;
|
||||
let open_tasks = project
|
||||
.update(&mut cx, |project, cx| {
|
||||
|
@ -229,7 +244,7 @@ impl ProjectDiffEditor {
|
|||
let mut new_entries = Vec::new();
|
||||
let mut buffers = HashMap::<
|
||||
ProjectEntryId,
|
||||
(text::BufferSnapshot, Model<Buffer>, BufferDiff),
|
||||
(text::BufferSnapshot, Entity<Buffer>, BufferDiff),
|
||||
>::default();
|
||||
let mut change_sets = Vec::new();
|
||||
for (entry_id, entry_path, open_task) in open_tasks {
|
||||
|
@ -258,7 +273,7 @@ impl ProjectDiffEditor {
|
|||
continue;
|
||||
};
|
||||
|
||||
cx.update(|cx| {
|
||||
cx.update(|_, cx| {
|
||||
buffers.insert(
|
||||
entry_id,
|
||||
(
|
||||
|
@ -307,7 +322,7 @@ impl ProjectDiffEditor {
|
|||
.await;
|
||||
|
||||
project_diff_editor
|
||||
.update(&mut cx, |project_diff_editor, cx| {
|
||||
.update_in(&mut cx, |project_diff_editor, _window, cx| {
|
||||
project_diff_editor.update_excerpts(id, new_changes, new_entry_order, cx);
|
||||
project_diff_editor.editor.update(cx, |editor, cx| {
|
||||
editor.buffer.update(cx, |buffer, cx| {
|
||||
|
@ -327,7 +342,8 @@ impl ProjectDiffEditor {
|
|||
worktree_id: WorktreeId,
|
||||
new_changes: HashMap<ProjectEntryId, Changes>,
|
||||
new_entry_order: Vec<(ProjectPath, ProjectEntryId)>,
|
||||
cx: &mut ViewContext<ProjectDiffEditor>,
|
||||
|
||||
cx: &mut Context<ProjectDiffEditor>,
|
||||
) {
|
||||
if let Some(current_order) = self.entry_order.get(&worktree_id) {
|
||||
let current_entries = self.buffer_changes.entry(worktree_id).or_default();
|
||||
|
@ -335,7 +351,7 @@ impl ProjectDiffEditor {
|
|||
let mut excerpts_to_remove = Vec::new();
|
||||
let mut new_excerpt_hunks = BTreeMap::<
|
||||
ExcerptId,
|
||||
Vec<(ProjectPath, Model<Buffer>, Vec<Range<text::Anchor>>)>,
|
||||
Vec<(ProjectPath, Entity<Buffer>, Vec<Range<text::Anchor>>)>,
|
||||
>::new();
|
||||
let mut excerpt_to_expand =
|
||||
HashMap::<(u32, ExpandExcerptDirection), Vec<ExcerptId>>::default();
|
||||
|
@ -902,8 +918,8 @@ impl ProjectDiffEditor {
|
|||
|
||||
impl EventEmitter<EditorEvent> for ProjectDiffEditor {}
|
||||
|
||||
impl FocusableView for ProjectDiffEditor {
|
||||
fn focus_handle(&self, _: &AppContext) -> FocusHandle {
|
||||
impl Focusable for ProjectDiffEditor {
|
||||
fn focus_handle(&self, _: &App) -> FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
@ -915,20 +931,26 @@ impl Item for ProjectDiffEditor {
|
|||
Editor::to_item_events(event, f)
|
||||
}
|
||||
|
||||
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.editor.update(cx, |editor, cx| editor.deactivated(cx));
|
||||
}
|
||||
|
||||
fn navigate(&mut self, data: Box<dyn Any>, cx: &mut ViewContext<Self>) -> bool {
|
||||
fn deactivated(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.editor
|
||||
.update(cx, |editor, cx| editor.navigate(data, cx))
|
||||
.update(cx, |editor, cx| editor.deactivated(window, cx));
|
||||
}
|
||||
|
||||
fn tab_tooltip_text(&self, _: &AppContext) -> Option<SharedString> {
|
||||
fn navigate(
|
||||
&mut self,
|
||||
data: Box<dyn Any>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> bool {
|
||||
self.editor
|
||||
.update(cx, |editor, cx| editor.navigate(data, window, cx))
|
||||
}
|
||||
|
||||
fn tab_tooltip_text(&self, _: &App) -> Option<SharedString> {
|
||||
Some("Project Diff".into())
|
||||
}
|
||||
|
||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
|
||||
fn tab_content(&self, params: TabContentParams, _window: &Window, _: &App) -> AnyElement {
|
||||
if self.buffer_changes.is_empty() {
|
||||
Label::new("No changes")
|
||||
.color(if params.selected {
|
||||
|
@ -978,17 +1000,22 @@ impl Item for ProjectDiffEditor {
|
|||
|
||||
fn for_each_project_item(
|
||||
&self,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
f: &mut dyn FnMut(gpui::EntityId, &dyn project::ProjectItem),
|
||||
) {
|
||||
self.editor.for_each_project_item(cx, f)
|
||||
}
|
||||
|
||||
fn is_singleton(&self, _: &AppContext) -> bool {
|
||||
fn is_singleton(&self, _: &App) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn set_nav_history(&mut self, nav_history: ItemNavHistory, cx: &mut ViewContext<Self>) {
|
||||
fn set_nav_history(
|
||||
&mut self,
|
||||
nav_history: ItemNavHistory,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.editor.update(cx, |editor, _| {
|
||||
editor.set_nav_history(Some(nav_history));
|
||||
});
|
||||
|
@ -997,59 +1024,63 @@ impl Item for ProjectDiffEditor {
|
|||
fn clone_on_split(
|
||||
&self,
|
||||
_workspace_id: Option<workspace::WorkspaceId>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<View<Self>>
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<Entity<Self>>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Some(cx.new_view(|cx| {
|
||||
ProjectDiffEditor::new(self.project.clone(), self.workspace.clone(), cx)
|
||||
Some(cx.new(|cx| {
|
||||
ProjectDiffEditor::new(self.project.clone(), self.workspace.clone(), window, cx)
|
||||
}))
|
||||
}
|
||||
|
||||
fn is_dirty(&self, cx: &AppContext) -> bool {
|
||||
fn is_dirty(&self, cx: &App) -> bool {
|
||||
self.excerpts.read(cx).is_dirty(cx)
|
||||
}
|
||||
|
||||
fn has_conflict(&self, cx: &AppContext) -> bool {
|
||||
fn has_conflict(&self, cx: &App) -> bool {
|
||||
self.excerpts.read(cx).has_conflict(cx)
|
||||
}
|
||||
|
||||
fn can_save(&self, _: &AppContext) -> bool {
|
||||
fn can_save(&self, _: &App) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn save(
|
||||
&mut self,
|
||||
format: bool,
|
||||
project: Model<Project>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
project: Entity<Project>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
self.editor.save(format, project, cx)
|
||||
self.editor.save(format, project, window, cx)
|
||||
}
|
||||
|
||||
fn save_as(
|
||||
&mut self,
|
||||
_: Model<Project>,
|
||||
_: Entity<Project>,
|
||||
_: ProjectPath,
|
||||
_: &mut ViewContext<Self>,
|
||||
_window: &mut Window,
|
||||
_: &mut Context<Self>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn reload(
|
||||
&mut self,
|
||||
project: Model<Project>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
project: Entity<Project>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
self.editor.reload(project, cx)
|
||||
self.editor.reload(project, window, cx)
|
||||
}
|
||||
|
||||
fn act_as_type<'a>(
|
||||
&'a self,
|
||||
type_id: TypeId,
|
||||
self_handle: &'a View<Self>,
|
||||
_: &'a AppContext,
|
||||
self_handle: &'a Entity<Self>,
|
||||
_: &'a App,
|
||||
) -> Option<AnyView> {
|
||||
if type_id == TypeId::of::<Self>() {
|
||||
Some(self_handle.to_any())
|
||||
|
@ -1060,22 +1091,28 @@ impl Item for ProjectDiffEditor {
|
|||
}
|
||||
}
|
||||
|
||||
fn breadcrumb_location(&self, _: &AppContext) -> ToolbarItemLocation {
|
||||
fn breadcrumb_location(&self, _: &App) -> ToolbarItemLocation {
|
||||
ToolbarItemLocation::PrimaryLeft
|
||||
}
|
||||
|
||||
fn breadcrumbs(&self, theme: &theme::Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {
|
||||
fn breadcrumbs(&self, theme: &theme::Theme, cx: &App) -> Option<Vec<BreadcrumbText>> {
|
||||
self.editor.breadcrumbs(theme, cx)
|
||||
}
|
||||
|
||||
fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext<Self>) {
|
||||
self.editor
|
||||
.update(cx, |editor, cx| editor.added_to_workspace(workspace, cx));
|
||||
fn added_to_workspace(
|
||||
&mut self,
|
||||
workspace: &mut Workspace,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
editor.added_to_workspace(workspace, window, cx)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ProjectDiffEditor {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let child = if self.buffer_changes.is_empty() {
|
||||
div()
|
||||
.bg(cx.theme().colors().editor_background)
|
||||
|
@ -1142,14 +1179,15 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), [Path::new("/root")], cx).await;
|
||||
let workspace = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace =
|
||||
cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
let cx = &mut VisualTestContext::from_window(*workspace.deref(), cx);
|
||||
|
||||
let file_a_editor = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, window, cx| {
|
||||
let file_a_editor =
|
||||
workspace.open_abs_path(PathBuf::from("/root/file_a"), true, cx);
|
||||
ProjectDiffEditor::deploy(workspace, &Deploy, cx);
|
||||
workspace.open_abs_path(PathBuf::from("/root/file_a"), true, window, cx);
|
||||
ProjectDiffEditor::deploy(workspace, &Deploy, window, cx);
|
||||
file_a_editor
|
||||
})
|
||||
.unwrap()
|
||||
|
@ -1158,7 +1196,7 @@ mod tests {
|
|||
.downcast::<Editor>()
|
||||
.expect("did not open an editor for file_a");
|
||||
let project_diff_editor = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
workspace
|
||||
.active_pane()
|
||||
.read(cx)
|
||||
|
@ -1177,14 +1215,14 @@ mod tests {
|
|||
let old_text = file_a_editor.update(cx, |editor, cx| editor.text(cx));
|
||||
let change = "an edit after git add";
|
||||
file_a_editor
|
||||
.update(cx, |file_a_editor, cx| {
|
||||
file_a_editor.insert(change, cx);
|
||||
file_a_editor.save(false, project.clone(), cx)
|
||||
.update_in(cx, |file_a_editor, window, cx| {
|
||||
file_a_editor.insert(change, window, cx);
|
||||
file_a_editor.save(false, project.clone(), window, cx)
|
||||
})
|
||||
.await
|
||||
.expect("failed to save a file");
|
||||
file_a_editor.update(cx, |file_a_editor, cx| {
|
||||
let change_set = cx.new_model(|cx| {
|
||||
file_a_editor.update_in(cx, |file_a_editor, _window, cx| {
|
||||
let change_set = cx.new(|cx| {
|
||||
BufferChangeSet::new_with_base_text(
|
||||
old_text.clone(),
|
||||
&file_a_editor.buffer().read(cx).as_singleton().unwrap(),
|
||||
|
@ -1223,7 +1261,7 @@ mod tests {
|
|||
cx.executor()
|
||||
.advance_clock(UPDATE_DEBOUNCE + Duration::from_millis(100));
|
||||
cx.run_until_parked();
|
||||
let editor = project_diff_editor.update(cx, |view, _| view.editor.clone());
|
||||
let editor = project_diff_editor.update(cx, |diff_editor, _| diff_editor.editor.clone());
|
||||
|
||||
assert_state_with_diff(
|
||||
&editor,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue