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 picker
Max Brunsfeldd690fb038df2
diff --cc crates/editor2/src/element.rsindex 5623374b3ee,09f9ef1a599..daff2b4f028--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@@ -8,10 -8,10 +8,10 @@@ use crate::use anyhow::Result;use collections::{BTreeMap, HashMap};use gpui::{- black, hsla, point, px, relative, size, transparent_black, AnyElement, BorrowWindow, Bounds,- ContentMask, Corners, DispatchPhase, Edges, Element, ElementId, Hsla, Line, Pixels,- ScrollWheelEvent, ShapedGlyph, Size, StatefulInteractivity, Style, TextRun, TextStyle,- TextSystem, ViewContext, WindowContext,+ black, hsla, point, px, relative, size, transparent_black, Action, AnyElement, BorrowWindow,+ Bounds, ContentMask, Corners, DispatchContext, DispatchPhase, Edges, Element, ElementId,+ Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Pixels, ScrollWheelEvent, ShapedGlyph,- Size, StatefulInteraction, Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext,++ Size, StatefulInteractivity, Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext,};use itertools::Itertools;use language::language_settings::ShowWhitespaceSetting;diff --cc crates/workspace2/src/modal_layer.rsindex 00000000000,e7cee53b2b3..76c18310efcmode 000000,100644..100644--- a/crates/workspace2/src/modal_layer.rs+++ b/crates/workspace2/src/modal_layer.rs@@@ -1,0 -1,121 +1,113 @@@+ use std::{any::TypeId, sync::Arc};++ use gpui::{- div, AnyView, AppContext, Component, DispatchPhase, Div, ParentElement, Render,- StatelessInteractive, View, ViewContext,++ div, AnyView, AppContext, Component, Div, ParentElement, Render, StatelessInteractive, View,++ ViewContext,+ };++ use crate::Workspace;++ pub struct ModalRegistry {+ registered_modals: Vec<(TypeId, Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>)>,+ }++ pub trait Modal {}++ #[derive(Clone)]+ pub struct ModalLayer {+ open_modal: Option<AnyView>,+ }++ pub fn init_modal_registry(cx: &mut AppContext) {+ cx.set_global(ModalRegistry {+ registered_modals: Vec::new(),+ });+ }++ struct ToggleModal {+ name: String,+ }++ // complete change of plan?+ // on_action(ToggleModal{ name})+ // register_modal(name, |workspace, cx| { ... })++ impl ModalRegistry {+ pub fn register_modal<A: 'static, V, B>(&mut self, action: A, build_view: B)+ where+ V: Render,+ B: Fn(&Workspace, &mut ViewContext<Workspace>) -> View<V> + 'static,+ {+ let build_view = Arc::new(build_view);++ dbg!("yonder");+ self.registered_modals.push((+ TypeId::of::<A>(),+ Box::new(move |mut div| {+ let build_view = build_view.clone();+ dbg!("this point");++ div.on_action(- move |workspace: &mut Workspace,- event: &A,- phase: DispatchPhase,- cx: &mut ViewContext<Workspace>| {- dbg!("GOT HERE");- if phase == DispatchPhase::Capture {- return;- }-++ move |workspace: &mut Workspace, event: &A, cx: &mut ViewContext<Workspace>| {+ let new_modal = (build_view)(workspace, cx);+ workspace.modal_layer.update(cx, |modal_layer, _| {+ modal_layer.open_modal = Some(new_modal.into());+ });++ cx.notify();+ },+ )+ }),+ ));+ }+ }++ impl ModalLayer {+ pub fn new() -> Self {+ Self { open_modal: None }+ }++ pub fn render(&self, cx: &ViewContext<Workspace>) -> impl Component<Workspace> {+ dbg!("rendering ModalLayer");++ let mut div = div();++ // div, c workspace.toggle_modal()div.on_action()) {+ //+ // }++ // for (type_id, action) in cx.global::<ModalRegistry>().registered_modals.iter() {+ // div = div.useful_on_action(*type_id, action)+ // }++ for (_, action) in cx.global::<ModalRegistry>().registered_modals.iter() {+ div = (action)(div);+ }++ div.children(self.open_modal.clone())+ }+ }++ // impl Render for ModalLayer {+ // type Element = Div<Self>;++ // fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {+ // let mut div = div();+ // for (type_id, build_view) in cx.global::<ModalRegistry>().registered_modals {+ // div = div.useful_on_action(+ // type_id,+ // Box::new(|this, _: dyn Any, phase, cx: &mut ViewContext<Self>| {+ // if phase == DispatchPhase::Capture {+ // return;+ // }+ // self.workspace.update(cx, |workspace, cx| {+ // self.open_modal = Some(build_view(workspace, cx));+ // });+ // cx.notify();+ // }),+ // )+ // }++ // div+ // }+ // }