Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Move `render_view` into `View::render_with`
Antonio Scandurrac7b7f7dfd5c3
diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rsindex 41757b4dc27..af7da8e8371 100644--- a/crates/editor2/src/editor.rs+++ b/crates/editor2/src/editor.rs@@ -39,12 +39,12 @@ use futures::FutureExt;use fuzzy::{StringMatch, StringMatchCandidate};use git::diff_hunk_to_display;use gpui::{- action, actions, div, point, prelude::*, px, relative, rems, render_view, size, uniform_list,- AnyElement, AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem,- Component, Context, EventEmitter, FocusHandle, FontFeatures, FontStyle, FontWeight,- HighlightStyle, Hsla, InputHandler, KeyContext, Model, MouseButton, ParentComponent, Pixels,- Render, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext,- VisualContext, WeakView, WindowContext,+ action, actions, div, point, prelude::*, px, relative, rems, size, uniform_list, AnyElement,+ AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Component, Context,+ EventEmitter, FocusHandle, FontFeatures, FontStyle, FontWeight, HighlightStyle, Hsla,+ InputHandler, KeyContext, Model, MouseButton, ParentComponent, Pixels, Render, Styled,+ Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext, VisualContext,+ WeakView, WindowContext,};use highlight_matching_bracket::refresh_matching_bracket_highlights;use hover_popover::{hide_hover, HoverState};@@ -7777,25 +7777,18 @@ impl Editor {}div().pl(cx.anchor_x)- .child(render_view(+ .child(rename_editor.render_with(EditorElement::new(&rename_editor,- EditorElement::new(- &rename_editor,- EditorStyle {- background: cx.theme().system().transparent,- local_player: cx.editor_style.local_player,- text: text_style,- scrollbar_width: cx- .editor_style- .scrollbar_width,- syntax: cx.editor_style.syntax.clone(),- diagnostic_style: cx- .editor_style- .diagnostic_style- .clone(),- },- ),- ))+ EditorStyle {+ background: cx.theme().system().transparent,+ local_player: cx.editor_style.local_player,+ text: text_style,+ scrollbar_width: cx.editor_style.scrollbar_width,+ syntax: cx.editor_style.syntax.clone(),+ diagnostic_style:+ cx.editor_style.diagnostic_style.clone(),+ },+ ))).render()}}),diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rsindex c0bbe00db63..5a2cc0f1036 100644--- a/crates/gpui2/src/view.rs+++ b/crates/gpui2/src/view.rs@@ -63,6 +63,16 @@ impl<V: 'static> View<V> {pub fn read<'a>(&self, cx: &'a AppContext) -> &'a V {self.model.read(cx)}++ pub fn render_with<C>(&self, component: C) -> RenderViewWith<C, V>+ where+ C: 'static + Component<V>,+ {+ RenderViewWith {+ view: self.clone(),+ component: Some(component),+ }+ }}impl<V> Clone for View<V> {@@ -281,12 +291,12 @@ where}}-pub struct RenderView<C, V> {+pub struct RenderViewWith<C, V> {view: View<V>,component: Option<C>,}-impl<C, ParentViewState, ViewState> Component<ParentViewState> for RenderView<C, ViewState>+impl<C, ParentViewState, ViewState> Component<ParentViewState> for RenderViewWith<C, ViewState>whereC: 'static + Component<ViewState>,ParentViewState: 'static,@@ -297,7 +307,7 @@ where}}-impl<C, ParentViewState, ViewState> Element<ParentViewState> for RenderView<C, ViewState>+impl<C, ParentViewState, ViewState> Element<ParentViewState> for RenderViewWith<C, ViewState>whereC: 'static + Component<ViewState>,ParentViewState: 'static,@@ -348,17 +358,6 @@ where}}-pub fn render_view<C, V>(view: &View<V>, component: C) -> RenderView<C, V>-where- C: 'static + Component<V>,- V: 'static,-{- RenderView {- view: view.clone(),- component: Some(component),- }-}-mod any_view {use crate::{AnyElement, AnyView, BorrowWindow, LayoutId, Render, WindowContext};use std::any::Any;