Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP
Nathan Sobo3c938a7377bb
diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rsindex bd615522c26..9b847e9c0cf 100644--- a/crates/gpui/src/app.rs+++ b/crates/gpui/src/app.rs@@ -130,10 +130,12 @@ pub trait BorrowAppContext {}pub trait BorrowWindowContext {- fn read_with<T, F>(&self, window_id: usize, f: F) -> T+ type Return<T>;++ fn read_with<T, F>(&self, window_id: usize, f: F) -> Self::Return<T>whereF: FnOnce(&WindowContext) -> T;- fn update<T, F>(&mut self, window_id: usize, f: F) -> T+ fn update<T, F>(&mut self, window_id: usize, f: F) -> Self::Return<T>whereF: FnOnce(&mut WindowContext) -> T;}@@ -3358,6 +3360,8 @@ impl<V> BorrowAppContext for ViewContext<'_, '_, V> {}impl<V> BorrowWindowContext for ViewContext<'_, '_, V> {+ type Return<T> = T;+fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {BorrowWindowContext::read_with(&*self.window_context, window_id, f)}@@ -3463,6 +3467,8 @@ impl<V: View> BorrowAppContext for LayoutContext<'_, '_, '_, V> {}impl<V: View> BorrowWindowContext for LayoutContext<'_, '_, '_, V> {+ type Return<T> = T;+fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {BorrowWindowContext::read_with(&*self.view_context, window_id, f)}@@ -3515,6 +3521,8 @@ impl<V: View> BorrowAppContext for EventContext<'_, '_, '_, V> {}impl<V: View> BorrowWindowContext for EventContext<'_, '_, '_, V> {+ type Return<T> = T;+fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {BorrowWindowContext::read_with(&*self.view_context, window_id, f)}@@ -4013,7 +4021,7 @@ impl<T: View> ViewHandle<T> {cx.read_view(self)}- pub fn read_with<C, F, S>(&self, cx: &C, read: F) -> S+ pub fn read_with<C, F, S>(&self, cx: &C, read: F) -> C::Return<S>whereC: BorrowWindowContext,F: FnOnce(&T, &ViewContext<T>) -> S,@@ -4024,7 +4032,7 @@ impl<T: View> ViewHandle<T> {})}- pub fn update<C, F, S>(&self, cx: &mut C, update: F) -> S+ pub fn update<C, F, S>(&self, cx: &mut C, update: F) -> C::Return<S>whereC: BorrowWindowContext,F: FnOnce(&mut T, &mut ViewContext<T>) -> S,diff --git a/crates/gpui/src/app/test_app_context.rs b/crates/gpui/src/app/test_app_context.rsindex 80f10374665..5c7947a4482 100644--- a/crates/gpui/src/app/test_app_context.rs+++ b/crates/gpui/src/app/test_app_context.rs@@ -406,6 +406,8 @@ impl BorrowAppContext for TestAppContext {}impl BorrowWindowContext for TestAppContext {+ type Return<T> = T;+fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {self.cx.borrow()diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rsindex 7cdcbc2c8fc..671d2b38c77 100644--- a/crates/gpui/src/app/window.rs+++ b/crates/gpui/src/app/window.rs@@ -142,6 +142,8 @@ impl BorrowAppContext for WindowContext<'_> {}impl BorrowWindowContext for WindowContext<'_> {+ type Return<T> = T;+fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {if self.window_id == window_id {f(self)