Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Recall empty, unsaved buffers on app load (#33475)
vipex12bc8907d926
diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rsindex 4e6e471f48e..ca635a21327 100644--- a/crates/editor/src/items.rs+++ b/crates/editor/src/items.rs@@ -1226,7 +1226,20 @@ impl SerializableItem for Editor {abs_path: None,contents: None,..- } => Task::ready(Err(anyhow!("No path or contents found for buffer"))),+ } => window.spawn(cx, async move |cx| {+ let buffer = project+ .update(cx, |project, cx| project.create_buffer(cx))?+ .await?;++ cx.update(|window, cx| {+ cx.new(|cx| {+ let mut editor = Editor::for_buffer(buffer, Some(project), window, cx);++ editor.read_metadata_from_db(item_id, workspace_id, window, cx);+ editor+ })+ })+ }),}}@@ -2098,5 +2111,38 @@ mod tests {assert!(editor.has_conflict(cx)); // The editor should have a conflict});}++ // Test case 5: Deserialize with no path, no content, no language, and no old mtime (new, empty, unsaved buffer)+ {+ let project = Project::test(fs.clone(), [path!("/file.rs").as_ref()], cx).await;+ let (workspace, cx) =+ cx.add_window_view(|window, cx| Workspace::test_new(project.clone(), window, cx));++ let workspace_id = workspace::WORKSPACE_DB.next_id().await.unwrap();++ let item_id = 10000 as ItemId;+ let serialized_editor = SerializedEditor {+ abs_path: None,+ contents: None,+ language: None,+ mtime: None,+ };++ DB.save_serialized_editor(item_id, workspace_id, serialized_editor)+ .await+ .unwrap();++ let deserialized =+ deserialize_editor(item_id, workspace_id, workspace, project, cx).await;++ deserialized.update(cx, |editor, cx| {+ assert_eq!(editor.text(cx), "");+ assert!(!editor.is_dirty(cx));+ assert!(!editor.has_conflict(cx));++ let buffer = editor.buffer().read(cx).as_singleton().unwrap().read(cx);+ assert!(buffer.file().is_none());+ });+ }}}