diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index ce810bab0c508bb04c4c56c79af614f8fdbc02df..d1ccc5e8f3020a420fd46f383d6add7961954c64 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -373,6 +373,7 @@ pub fn init(cx: &mut MutableAppContext) { workspace::register_project_item::(cx); workspace::register_followable_item::(cx); + workspace::register_deserializable_item::(cx); } trait InvalidationRegion { diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index ae9bbd57484ec04f5b1f8e304e5e4f274c747234..005012294868881a52aed66cbc2a9ee388160b4a 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -1,9 +1,9 @@ use crate::{ display_map::ToDisplayPoint, link_go_to_definition::hide_link_definition, - movement::surrounding_word, Anchor, Autoscroll, Editor, Event, ExcerptId, MultiBuffer, - MultiBufferSnapshot, NavigationData, ToPoint as _, FORMAT_TIMEOUT, + movement::surrounding_word, Anchor, Autoscroll, Editor, EditorMode, Event, ExcerptId, + MultiBuffer, MultiBufferSnapshot, NavigationData, ToPoint as _, FORMAT_TIMEOUT, }; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Context, Result}; use futures::FutureExt; use gpui::{ elements::*, geometry::vector::vec2f, AppContext, Entity, ModelHandle, MutableAppContext, @@ -558,14 +558,36 @@ impl Item for Editor { } fn deserialize( - _project: ModelHandle, + project: ModelHandle, _workspace: WeakViewHandle, _workspace_id: WorkspaceId, _item_id: ItemId, - _cx: &mut ViewContext, + cx: &mut ViewContext, ) -> Task>> { // Look up the path with this key associated, create a self with that path - unimplemented!() + let path = Path::new("."); + if let Some(project_item) = project.update(cx, |project, cx| { + let (worktree, path) = project.find_local_worktree(path, cx)?; + let project_path = ProjectPath { + worktree_id: worktree.read(cx).id(), + path: path.into(), + }; + + Some(project.open_path(project_path, cx)) + }) { + cx.spawn(|pane, mut cx| async move { + let (_, project_item) = project_item.await?; + let buffer = project_item + .downcast::() + .context("Project item at stored path was not a buffer")?; + + Ok(cx.update(|cx| { + cx.add_view(pane, |cx| Editor::for_buffer(buffer, Some(project), cx)) + })) + }) + } else { + Task::ready(Err(anyhow!("Could not load file from stored path"))) + } } } diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 15b3b4e66ed7b7f71bf91408c091bc313378d34a..66a64903d354ea111622428aa197029457ac0fc4 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -69,8 +69,6 @@ use lazy_static::lazy_static; pub fn init(cx: &mut MutableAppContext) { terminal_view::init(cx); terminal_container_view::init(cx); - - register_deserializable_item::(cx); } ///Scrolling is unbearably sluggish by default. Alacritty supports a configurable