Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
wip serialize editor
Kay Simmons75d3d46b1b75
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex ce810bab0c5..d1ccc5e8f30 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::<Editor>(cx);workspace::register_followable_item::<Editor>(cx);+ workspace::register_deserializable_item::<Editor>(cx);}trait InvalidationRegion {diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rsindex ae9bbd57484..00501229486 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>,+ project: ModelHandle<Project>,_workspace: WeakViewHandle<Workspace>,_workspace_id: WorkspaceId,_item_id: ItemId,- _cx: &mut ViewContext<Pane>,+ cx: &mut ViewContext<Pane>,) -> Task<Result<ViewHandle<Self>>> {// 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::<Buffer>()+ .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.rsindex 15b3b4e66ed..66a64903d35 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::<TerminalContainer>(cx);}///Scrolling is unbearably sluggish by default. Alacritty supports a configurable