Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'main' into derive-element-redux
Conrad Irwin0798cfd58cc7
diff --cc crates/command_palette2/src/command_palette.rsindex cf3be8379ad,f3573c1a3da..ef8e4cb5fe3--- a/crates/command_palette2/src/command_palette.rs+++ b/crates/command_palette2/src/command_palette.rs@@@ -1,8 -1,9 +1,9 @@@use collections::{CommandPaletteFilter, HashMap};use fuzzy::{StringMatch, StringMatchCandidate};use gpui::{- actions, div, prelude::*, Action, AppContext, Dismiss, Div, FocusHandle, Keystroke,- ManagedView, ParentElement, Render, Styled, View, ViewContext, VisualContext, WeakView,- actions, div, prelude::*, Action, AppContext, Component, Div, EventEmitter, FocusHandle,- FocusableView, Keystroke, Manager, ParentComponent, Render, Styled, View, ViewContext,- VisualContext, WeakView,++ actions, actions, div, prelude::*, prelude::*, Action, AppContext, Component, Dismiss, Div,++ EventEmitter, FocusHandle, FocusableView, Keystroke, ManagedView, Manager, ParentComponent,++ ParentElement, Render, Render, Styled, View, ViewContext, VisualContext, WeakView,};use picker::{Picker, PickerDelegate};use std::{diff --cc crates/editor2/src/element.rsindex a207e064c58,220fe89ea65..42cb47da495--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@@ -2049,13 -2048,10 +2051,14 @@@ impl EditorElement}h_stack()+ .id("path header block").size_full().bg(gpui::red())- .child(filename.unwrap_or_else(|| "untitled".to_string()))+ .child(+ filename+ .map(SharedString::from)+ .unwrap_or_else(|| "untitled".into()),+ ).children(parent_path).children(jump_icon) // .p_x(gutter_padding)} else {diff --cc crates/file_finder2/src/file_finder.rsindex 77bc14fa96a,3691e69f5dc..60ebc9138bc--- a/crates/file_finder2/src/file_finder.rs+++ b/crates/file_finder2/src/file_finder.rs@@@ -2,8 -2,9 +2,10 @@@ use collections::HashMapuse editor::{scroll::autoscroll::Autoscroll, Bias, Editor};use fuzzy::{CharBag, PathMatch, PathMatchCandidate};use gpui::{- actions, div, AppContext, Dismiss, Div, FocusHandle, InteractiveElement, ManagedView, Model,- ParentElement, Render, RenderOnce, Styled, Task, View, ViewContext, VisualContext, WeakView,- actions, div, AppContext, Component, Div, EventEmitter, FocusHandle, FocusableView,- InteractiveComponent, Manager, Model, ParentComponent, Render, Styled, Task, View, ViewContext,- VisualContext, WeakView,++ actions, div, AppContext, Component, Dismiss, Div, EventEmitter, FocusHandle, FocusableView,++ InteractiveComponent, InteractiveElement, ManagedView, Manager, Model, ParentComponent,++ ParentElement, Render, RenderOnce, Styled, Styled, Task, View, ViewContext, VisualContext,++ WeakView,};use picker::{Picker, PickerDelegate};use project::{PathMatchCandidateSet, Project, ProjectPath, WorktreeId};diff --cc crates/gpui2/src/elements/text.rsindex 9c7cd35e25d,e3c63523e12..b5fd6e8774d--- a/crates/gpui2/src/elements/text.rs+++ b/crates/gpui2/src/elements/text.rs@@@ -205,91 -151,13 +223,93 @@@ pub struct TextState(Arc<Mutex<Option<Tstruct TextStateInner {lines: SmallVec<[WrappedLine; 1]>,line_height: Pixels,+ wrap_width: Option<Pixels>,+ size: Option<Size<Pixels>>,}+impl TextState {+ fn lock(&self) -> MutexGuard<Option<TextStateInner>> {+ self.0.lock()+ }++ fn layout(+ &mut self,+ text: SharedString,+ runs: Option<Vec<TextRun>>,+ cx: &mut WindowContext,+ ) -> LayoutId {+ let text_system = cx.text_system().clone();+ let text_style = cx.text_style();+ let font_size = text_style.font_size.to_pixels(cx.rem_size());+ let line_height = text_style+ .line_height+ .to_pixels(font_size.into(), cx.rem_size());+ let text = SharedString::from(text);++ let rem_size = cx.rem_size();++ let runs = if let Some(runs) = runs {+ runs+ } else {+ vec![text_style.to_run(text.len())]+ };++ let layout_id = cx.request_measured_layout(Default::default(), rem_size, {+ let element_state = self.clone();+ move |known_dimensions, _| {+ let Some(lines) = text_system+ .shape_text(+ &text,+ font_size,+ &runs[..],+ known_dimensions.width, // Wrap if we know the width.+ )+ .log_err()+ else {+ element_state.lock().replace(TextStateInner {+ lines: Default::default(),+ line_height,+ });+ return Size::default();+ };++ let mut size: Size<Pixels> = Size::default();+ for line in &lines {+ let line_size = line.size(line_height);+ size.height += line_size.height;+ size.width = size.width.max(line_size.width);+ }++ element_state+ .lock()+ .replace(TextStateInner { lines, line_height });++ size+ }+ });++ layout_id+ }++ fn paint(&mut self, bounds: Bounds<Pixels>, text: &str, cx: &mut WindowContext) {+ let element_state = self.lock();+ let element_state = element_state+ .as_ref()+ .ok_or_else(|| anyhow!("measurement has not been performed on {}", text))+ .unwrap();++ let line_height = element_state.line_height;+ let mut line_origin = bounds.origin;+ for line in &element_state.lines {+ line.paint(line_origin, line_height, cx).log_err();+ line_origin.y += line.size(line_height).height;+ }+ }+}+struct InteractiveText {id: ElementId,- text: Text,+ text: StyledText,}struct InteractiveTextState {diff --cc crates/gpui2/src/view.rsindex 6d6863b54b7,c1750d6dc54..a1ed8373c5e--- a/crates/gpui2/src/view.rs+++ b/crates/gpui2/src/view.rs@@@ -309,30 -281,45 +313,18 @@@ impl<V: 'static + Render<V>> From<WeakV}}- impl<F, E> Render<F> for F- where- F: 'static + FnMut(&mut WindowContext) -> E,- E: 'static + Send + Element<F>,- {- type Element = E;-// impl<T, E> Render for T-// where-// T: 'static + FnMut(&mut WindowContext) -> E,-// E: 'static + Send + Element<T>,-// {-// type Element = E;--- fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {- (self)(cx)- }- }-// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {-// (self)(cx)-// }-// }---pub struct RenderViewWith<C, V> {+pub struct RenderViewWith<E, V> {view: View<V>,- component: Option<C>,-}--impl<C, ParentViewState, ViewState> Component<ParentViewState> for RenderViewWith<C, ViewState>-where- C: 'static + Component<ViewState>,- ParentViewState: 'static,- ViewState: 'static,-{- fn render(self) -> AnyElement<ParentViewState> {- AnyElement::new(self)- }+ element: Option<E>,}-impl<C, ParentViewState, ViewState> Element<ParentViewState> for RenderViewWith<C, ViewState>+impl<E, ParentV, V> Element<ParentV> for RenderViewWith<E, V>where- C: 'static + Component<ViewState>,- ParentViewState: 'static,- ViewState: 'static,+ E: 'static + Element<V>,+ ParentV: 'static,+ V: 'static,{- type ElementState = AnyElement<ViewState>;-- fn element_id(&self) -> Option<ElementId> {- Some(self.view.entity_id().into())- }+ type State = Option<AnyElement<V>>;fn layout(&mut self,diff --cc crates/gpui2/src/window.rsindex 1b3b37c2900,a3fe05d39fe..cfd30eb5b61--- a/crates/gpui2/src/window.rs+++ b/crates/gpui2/src/window.rs@@@ -1,15 -1,15 +1,15 @@@use crate::{- key_dispatch::DispatchActionListener, px, size, Action, AnyBox, AnyDrag, AnyView, AppContext,+ key_dispatch::DispatchActionListener, px, size, Action, AnyDrag, AnyView, AppContext,AsyncWindowContext, AvailableSpace, Bounds, BoxShadow, Context, Corners, CursorStyle,DevicePixels, DispatchNodeId, DispatchTree, DisplayId, Edges, Effect, Entity, EntityId,- EventEmitter, FileDropEvent, Flatten, FocusEvent, FontId, GlobalElementId, GlyphId, Hsla,- ImageData, InputEvent, IsZero, KeyBinding, KeyContext, KeyDownEvent, LayoutId, Model,- ModelContext, Modifiers, MonochromeSprite, MouseButton, MouseDownEvent, MouseMoveEvent,- MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler,- PlatformWindow, Point, PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams,- RenderImageParams, RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size,- Style, SubscriberSet, Subscription, TaffyLayoutEngine, Task, Underline, UnderlineStyle, View,- VisualContext, WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS,+ EventEmitter, FileDropEvent, FocusEvent, FontId, GlobalElementId, GlyphId, Hsla, ImageData,+ InputEvent, IsZero, KeyBinding, KeyContext, KeyDownEvent, LayoutId, Model, ModelContext,+ Modifiers, MonochromeSprite, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path,+ Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point,- PolychromeSprite, PromptLevel, Quad, RenderGlyphParams, RenderImageParams, RenderSvgParams,- Render, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, SubscriberSet,++ PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams, RenderImageParams,++ RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, SubscriberSet,+ Subscription, TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext,+ WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS,};use anyhow::{anyhow, Context as _, Result};use collections::HashMap;diff --cc crates/storybook2/src/stories/text.rsindex 722832c76a2,512d680d377..716004dea71--- a/crates/storybook2/src/stories/text.rs+++ b/crates/storybook2/src/stories/text.rs@@@ -1,4 -1,7 +1,7 @@@- use gpui::{div, white, Div, ParentElement, Render, Styled, View, VisualContext, WindowContext};+ use gpui::{- blue, div, red, white, Div, ParentComponent, Render, Styled, View, VisualContext, WindowContext,++ blue, div, red, white, Div, ParentElement, Render, Styled, View, VisualContext, WindowContext,+ };+ use ui::v_stack;pub struct TextStory;diff --cc crates/terminal_view2/src/terminal_view.rsindex 079f2b9f88b,27e55602fb8..0c099de76d5--- a/crates/terminal_view2/src/terminal_view.rs+++ b/crates/terminal_view2/src/terminal_view.rs@@@ -755,9 -754,9 +754,9 @@@ impl Item for TerminalViewlet title = self.terminal().read(cx).title();div()- .child(img().uri("icons/terminal.svg").bg(red()))- .child(SharedString::from(title))+ .child(IconElement::new(Icon::Terminal))+ .child(title)- .render()+ .into_any()}fn clone_on_split(diff --cc crates/ui2/src/components/context_menu.rsindex 6235704d7ea,fe18cfaff99..bbb82e7f1bd--- a/crates/ui2/src/components/context_menu.rs+++ b/crates/ui2/src/components/context_menu.rs@@@ -4,18 -4,28 +4,34 @@@ use std::rc::Rcuse crate::prelude::*;use crate::{v_stack, Label, List, ListEntry, ListItem, ListSeparator, ListSubHeader};use gpui::{++<<<<<<< HEAD+ overlay, px, Action, AnchorCorner, AnyElement, Bounds, Dismiss, DispatchPhase, Div,+ FocusHandle, LayoutId, ManagedView, MouseButton, MouseDownEvent, Pixels, Point, Render,+ RenderOnce, View,++=======+ overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, DispatchPhase, Div,+ EventEmitter, FocusHandle, FocusableView, LayoutId, ManagedView, Manager, MouseButton,+ MouseDownEvent, Pixels, Point, Render, View, VisualContext, WeakView,++>>>>>>> main};- pub struct ContextMenu {- items: Vec<ListItem>,+ pub enum ContextMenuItem<V> {+ Separator(ListSeparator),+ Header(ListSubHeader),+ Entry(+ ListEntry<ContextMenu<V>>,+ Rc<dyn Fn(&mut V, &mut ViewContext<V>)>,+ ),+ }++ pub struct ContextMenu<V> {+ items: Vec<ContextMenuItem<V>>,focus_handle: FocusHandle,+ handle: WeakView<V>,}- impl ManagedView for ContextMenu {- fn focus_handle(&self, cx: &gpui::AppContext) -> FocusHandle {+ impl<V: Render> FocusableView for ContextMenu<V> {+ fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {self.focus_handle.clone()}}@@@ -53,9 -86,9 +92,13 @@@ impl<V: Render> ContextMenu<V>}}++<<<<<<< HEAD+impl Render<Self> for ContextMenu {++=======+ impl<V: Render> Render for ContextMenu<V> {++>>>>>>> maintype Element = Div<Self>;- // todo!()+fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {div().elevation_2(cx).flex().flex_row().child(v_stack()diff --cc crates/ui2/src/components/keybinding.rsindex ce7c408fb2a,69396274fab..fa5898d0cac--- a/crates/ui2/src/components/keybinding.rs+++ b/crates/ui2/src/components/keybinding.rs@@@ -88,19 -86,13 +94,19 @@@ pub use stories::*#[cfg(feature = "stories")]mod stories {use super::*;- use crate::Story;+ pub use crate::KeyBinding;+ use crate::{binding, Story};- use gpui::{Div, Render};+ use gpui::{actions, Div, Render};use itertools::Itertools;-pub struct KeybindingStory;+ actions!(NoAction);++ pub fn binding(key: &str) -> gpui::KeyBinding {+ gpui::KeyBinding::new(key, NoAction {}, None)+ }+- impl Render<Self> for KeybindingStory {+ impl Render for KeybindingStory {type Element = Div<Self>;fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {diff --cc crates/ui2/src/components/list.rsindex b183c149fcd,07ff577ce02..29510f873f9--- a/crates/ui2/src/components/list.rs+++ b/crates/ui2/src/components/list.rs@@@ -1,5 -1,7 +1,6 @@@+use gpui::{div, Action, Div, RenderOnce};+ use std::rc::Rc;-use gpui::{div, Div, Stateful, StatefulInteractiveComponent};-use crate::settings::user_settings;use crate::{disclosure_control, h_stack, v_stack, Avatar, Icon, IconElement, IconSize, Label, Toggle,@@@ -231,9 -174,9 +232,9 @@@ pub enum ListEntrySizeMedium,}-#[derive(Clone)]+#[derive(RenderOnce, Clone)]- pub enum ListItem {- Entry(ListEntry),+ pub enum ListItem<V: 'static> {+ Entry(ListEntry<V>),Separator(ListSeparator),Header(ListSubHeader),}@@@ -256,12 -199,10 +257,12 @@@ impl<V: 'static> From<ListSubHeader> fo}}- impl<V: 'static> Component<V> for ListItem {-impl<V: 'static> ListItem<V> {- fn render(self, view: &mut V, ix: usize, cx: &mut ViewContext<V>) -> impl Component<V> {++impl<V: 'static> Component<V> for ListItem<V> {+ type Rendered = Div<V>;++ fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {match self {- ListItem::Entry(entry) => div().child(entry.render(view, cx)),+ ListItem::Entry(entry) => div().child(entry.render(ix, cx)),ListItem::Separator(separator) => div().child(separator.render(view, cx)),ListItem::Header(header) => div().child(header.render(view, cx)),}@@@ -282,8 -221,7 +283,8 @@@ impl ListItem}}+// #[derive(RenderOnce)]- pub struct ListEntry {+ pub struct ListEntry<V> {disabled: bool,// TODO: Reintroduce this// disclosure_control_style: DisclosureControlVisibility,@@@ -457,9 -389,9 +456,9 @@@ impl<V: 'static> Component<V> for ListS}}-#[derive(Component)]+#[derive(RenderOnce)]- pub struct List {+ pub struct List<V: 'static> {- items: Vec<ListItem<V>>,+ items: Vec<ListItem>,/// Message to display when the list is empty/// Defaults to "No items"empty_message: SharedString,@@@ -467,28 -399,8 +466,28 @@@toggle: Toggle,}- impl<V: 'static> Component<V> for List {++impl<V: 'static> Component<V> for List<V> {+ type Rendered = Div<V>;++ fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {+ let list_content = match (self.items.is_empty(), self.toggle) {+ (false, _) => div().children(self.items),+ (true, Toggle::Toggled(false)) => div(),+ (true, _) => {+ div().child(Label::new(self.empty_message.clone()).color(TextColor::Muted))+ }+ };++ v_stack()+ .w_full()+ .py_1()+ .children(self.header.map(|header| header))+ .child(list_content)+ }+}+- impl List {+ impl<V: 'static> List<V> {- pub fn new(items: Vec<ListItem<V>>) -> Self {+ pub fn new(items: Vec<ListItem>) -> Self {Self {items,empty_message: "No items".into(),@@@ -512,9 -424,14 +511,14 @@@self}- fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {+ fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {let list_content = match (self.items.is_empty(), self.toggle) {- (false, _) => div().children(self.items),+ (false, _) => div().children(+ self.items+ .into_iter()+ .enumerate()+ .map(|(ix, item)| item.render(view, ix, cx)),+ ),(true, Toggle::Toggled(false)) => div(),(true, _) => {div().child(Label::new(self.empty_message.clone()).color(TextColor::Muted))diff --cc crates/workspace2/src/dock.rsindex f143b2c2e54,5df9ce7f455..9d812676038--- a/crates/workspace2/src/dock.rs+++ b/crates/workspace2/src/dock.rs@@@ -653,9 -705,33 +705,32 @@@ impl Render<Self> for PanelButtons};Some(- menu_handle()- .id(name)+ menu_handle(name).menu(move |_, cx| {- cx.build_view(|cx| ContextMenu::new(cx).header("SECTION"))+ const POSITIONS: [DockPosition; 3] = [+ DockPosition::Left,+ DockPosition::Right,+ DockPosition::Bottom,+ ];+ ContextMenu::build(cx, |mut menu, cx| {+ for position in POSITIONS {+ if position != dock_position+ && panel.position_is_valid(position, cx)+ {+ let panel = panel.clone();+ menu = menu.entry(+ ListEntry::new(Label::new(format!(+ "Dock {}",+ position.to_label()+ ))),+ move |_, cx| {+ panel.set_position(position, cx);+ },+ )+ }+ }+ menu+ })}).anchor(menu_anchor).attach(menu_attach)diff --cc crates/workspace2/src/notifications.rsindex bb00973d5c5,b1df74c61af..df5bbfdd123--- a/crates/workspace2/src/notifications.rs+++ b/crates/workspace2/src/notifications.rs@@@ -13,8 -13,10 +13,10 @@@ pub enum NotificationEventDismiss,}-pub trait Notification: EventEmitter<NotificationEvent> + Render {}+pub trait Notification: EventEmitter<NotificationEvent> + Render<Self> {}+ impl<V: EventEmitter<NotificationEvent> + Render> Notification for V {}+pub trait NotificationHandle: Send {fn id(&self) -> EntityId;fn to_any(&self) -> AnyView;diff --cc crates/workspace2/src/status_bar.rsindex 945760260ce,2293b7475c6..894229a31df--- a/crates/workspace2/src/status_bar.rs+++ b/crates/workspace2/src/status_bar.rs@@@ -53,10 -53,10 +53,10 @@@ impl Render<Self> for StatusBar}impl StatusBar {- fn render_left_tools(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> {+ fn render_left_tools(&self, cx: &mut ViewContext<Self>) -> impl RenderOnce<Self> {h_stack().items_center()- .gap_1()+ .gap_2().children(self.left_items.iter().map(|item| item.to_any()))}