Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP
Kirill Bulatove8857d959b1c
diff --git a/crates/gpui2/src/app/async_context.rs b/crates/gpui2/src/app/async_context.rsindex 6802b5c1e1d..06da000ca68 100644--- a/crates/gpui2/src/app/async_context.rs+++ b/crates/gpui2/src/app/async_context.rs@@ -1,6 +1,6 @@use crate::{- AnyWindowHandle, AppContext, Context, Executor, MainThread, Model, ModelContext, Render,- Result, Task, View, ViewContext, VisualContext, WindowContext, WindowHandle,+ AnyView, AnyWindowHandle, AppContext, Context, Executor, MainThread, Model, ModelContext,+ Render, Result, Task, View, ViewContext, VisualContext, WindowContext, WindowHandle,};use anyhow::Context as _;use derive_more::{Deref, DerefMut};@@ -293,6 +293,10 @@ impl Context for AsyncWindowContext {impl VisualContext for AsyncWindowContext {type ViewContext<'a, V: 'static> = ViewContext<'a, V>;+ fn root_view(&self) -> Result<AnyView> {+ self.app.update_window(self.window, |cx| cx.root_view())+ }+fn build_view<V>(&mut self,build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,diff --git a/crates/gpui2/src/gpui2.rs b/crates/gpui2/src/gpui2.rsindex 5e5ac119d87..74cfed19590 100644--- a/crates/gpui2/src/gpui2.rs+++ b/crates/gpui2/src/gpui2.rs@@ -215,6 +215,10 @@ impl<C: Context> Context for MainThread<C> {impl<C: VisualContext> VisualContext for MainThread<C> {type ViewContext<'a, V: 'static> = MainThread<C::ViewContext<'a, V>>;+ fn root_view(&self) -> AnyView {+ self.0.root_view()+ }+fn build_view<V>(&mut self,build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rsindex 1df49899caa..e6046e14cfb 100644--- a/crates/gpui2/src/window.rs+++ b/crates/gpui2/src/window.rs@@ -1,14 +1,14 @@use crate::{px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace,Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, Edges, Effect,- Entity, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId, GlobalElementId, GlyphId,- Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch, KeyMatcher, Keystroke, LayoutId,- MainThread, MainThreadOnly, Model, ModelContext, Modifiers, MonochromeSprite, MouseButton,- MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformWindow,- Point, PolychromeSprite, Quad, Render, RenderGlyphParams, RenderImageParams, RenderSvgParams,- ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, Subscription, TaffyLayoutEngine,- Task, Underline, UnderlineStyle, View, VisualContext, WeakView, WindowOptions,- SUBPIXEL_VARIANTS,+ Entity, EntityId, EventEmitter, FileDropEvent, Flatten, FocusEvent, FontId, GlobalElementId,+ GlyphId, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch, KeyMatcher, Keystroke,+ LayoutId, MainThread, MainThreadOnly, Model, ModelContext, Modifiers, MonochromeSprite,+ MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas,+ PlatformWindow, Point, PolychromeSprite, Quad, Render, RenderGlyphParams, RenderImageParams,+ RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, Subscription,+ TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext, WeakView,+ WindowOptions, SUBPIXEL_VARIANTS,};use anyhow::Result;use collections::HashMap;@@ -316,8 +316,6 @@ impl<'a> WindowContext<'a> {Self { app, window }}- // fn replace_root(&mut )-/// Obtain a handle to the window that belongs to this context.pub fn window_handle(&self) -> AnyWindowHandle {self.window.handle@@ -1312,6 +1310,13 @@ impl Context for WindowContext<'_> {impl VisualContext for WindowContext<'_> {type ViewContext<'a, V: 'static> = ViewContext<'a, V>;+ fn root_view(&self) -> Self::Result<AnyView> {+ self.window+ .root_view+ .clone()+ .expect("we only take the root_view value when we draw")+ }+fn build_view<V>(&mut self,build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,@@ -1966,6 +1971,10 @@ impl<V> Context for ViewContext<'_, V> {impl<V: 'static> VisualContext for ViewContext<'_, V> {type ViewContext<'a, W: 'static> = ViewContext<'a, W>;+ fn root_view(&self) -> Self::Result<AnyView> {+ self.window_cx.root_view()+ }+fn build_view<W: 'static + Send>(&mut self,build_view: impl FnOnce(&mut Self::ViewContext<'_, W>) -> W,@@ -2034,20 +2043,20 @@ impl<V: 'static + Render> WindowHandle<V> {}}- pub fn update_root<R>(+ pub fn update_root<C, R>(&self,- cx: &mut AppContext,+ cx: &mut C,update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,- ) -> Result<R> {+ ) -> Result<R>+ where+ C: Context,+ {cx.update_window(self.any_handle, |cx| {- let root_view = cx- .window- .root_view- .clone()- .unwrap()- .downcast::<V>()- .unwrap();- root_view.update(cx, update)+ let x = Ok(cx.root_view()).flatten();++ // let root_view = x.unwrap().downcast::<V>().unwrap();+ // root_view.update(cx, update)+ todo!()})}}diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rsindex 08cfbc1ee50..e2413c819cf 100644--- a/crates/workspace2/src/workspace2.rs+++ b/crates/workspace2/src/workspace2.rs@@ -887,11 +887,9 @@ impl Workspace {.await.log_err();- cx.update_global(|_, cx| {- window.update_root(&mut cx, |_, cx| {- // todo!()- // cx.activate_window()- });+ window.update_root(&mut cx, |_, cx| {+ // todo!()+ // cx.activate_window()});let workspace = workspace.downgrade();