Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP
Mikayla097efdebc5f5
diff --git a/Cargo.lock b/Cargo.lockindex fcbf5a0f958..1e6d24df8c3 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -11279,6 +11279,7 @@ dependencies = ["libc","log","lsp2",+ "menu2","node_runtime","num_cpus","parking_lot 0.11.2",diff --git a/crates/go_to_line2/src/go_to_line.rs b/crates/go_to_line2/src/go_to_line.rsindex bb705427b1c..f6481fdbd95 100644--- a/crates/go_to_line2/src/go_to_line.rs+++ b/crates/go_to_line2/src/go_to_line.rs@@ -1,7 +1,7 @@use editor::Editor;use gpui::{- actions, div, AppContext, Div, EventEmitter, ParentElement, Render, SharedString, Styled, View,- ViewContext, VisualContext,+ actions, div, AppContext, Div, EventEmitter, ParentElement, Render, SharedString,+ StatelessInteractive, Styled, View, ViewContext, VisualContext,};use text::Point;use theme::ActiveTheme;@@ -9,7 +9,7 @@ use ui::{h_stack, modal, v_stack, Label, LabelColor};use util::paths::FILE_ROW_COLUMN_DELIMITER;use workspace::ModalRegistry;-actions!(Toggle, Cancel, Confirm);+actions!(Toggle);pub fn init(cx: &mut AppContext) {cx.global_mut::<ModalRegistry>()@@ -20,10 +20,6 @@ pub fn init(cx: &mut AppContext) {Some(cx.build_view(|cx| GoToLine::new(editor, cx)))});-- // cx.add_action(GoToLine::toggle);- // cx.add_action(GoToLine::confirm);- // cx.add_action(GoToLine::cancel);}pub struct GoToLine {@@ -37,7 +33,7 @@ pub enum Event {}impl EventEmitter for GoToLine {- type Event = Event;+ type Event = ModalEvent;}impl GoToLine {@@ -45,6 +41,7 @@ impl GoToLine {let line_editor = cx.build_view(|cx| {let mut editor = Editor::single_line(cx);editor.set_placeholder_text("Find something", cx);+ editor.focus(cx);editor});cx.subscribe(&line_editor, Self::on_line_editor_event)@@ -98,23 +95,24 @@ impl GoToLine {))}- // fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {- // cx.emit(Event::Dismissed);- // }-- // fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {- // if let Some(point) = self.point_from_query(cx) {- // self.active_editor.update(cx, |active_editor, cx| {- // let snapshot = active_editor.snapshot(cx).display_snapshot;- // let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);- // active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {- // s.select_ranges([point..point])- // });- // });- // }+ fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {+ println!("CANCLE");+ cx.emit(Event::Dismissed);+ }- // cx.emit(Event::Dismissed);- // }+ fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {+ // // if let Some(point) = self.point_from_query(cx) {+ // // self.active_editor.update(cx, |active_editor, cx| {+ // // let snapshot = active_editor.snapshot(cx).display_snapshot;+ // // let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);+ // // active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {+ // // s.select_ranges([point..point])+ // // });+ // // });+ // // }++ // cx.emit(Event::Dismissed);+ }fn status_text(&self) -> SharedString {"Default text".into()@@ -125,31 +123,35 @@ impl Render for GoToLine {type Element = Div<Self>;fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {- modal(cx).w_96().child(- v_stack()- .px_1()- .pt_0p5()- .gap_px()- .child(- v_stack()- .py_0p5()- .px_1()- .child(div().px_1().py_0p5().child(self.line_editor.clone())),- )- .child(- div()- .h_px()- .w_full()- .bg(cx.theme().colors().element_background),- )- .child(- h_stack()- .justify_between()- .px_2()- .py_1()- .child(Label::new(self.status_text()).color(LabelColor::Muted)),- ),- )+ modal(cx)+ .w_96()+ .on_action(Self::cancel)+ .on_action(Self::confirm)+ .child(+ v_stack()+ .px_1()+ .pt_0p5()+ .gap_px()+ .child(+ v_stack()+ .py_0p5()+ .px_1()+ .child(div().px_1().py_0p5().child(self.line_editor.clone())),+ )+ .child(+ div()+ .h_px()+ .w_full()+ .bg(cx.theme().colors().element_background),+ )+ .child(+ h_stack()+ .justify_between()+ .px_2()+ .py_1()+ .child(Label::new(self.status_text()).color(LabelColor::Muted)),+ ),+ )}}diff --git a/crates/gpui2/src/action.rs b/crates/gpui2/src/action.rsindex 4d89ba1826e..85149f5d55c 100644--- a/crates/gpui2/src/action.rs+++ b/crates/gpui2/src/action.rs@@ -123,6 +123,7 @@ pub fn register_action<A: Action>() {/// Construct an action based on its name and optional JSON parameters sourced from the keymap.pub fn build_action(name: &str, params: Option<serde_json::Value>) -> Result<Box<dyn Action>> {let lock = ACTION_REGISTRY.read();+let build_action = lock.builders_by_name.get(name)diff --git a/crates/menu2/src/menu2.rs b/crates/menu2/src/menu2.rsindex e5e8242f37e..eafb1e295f7 100644--- a/crates/menu2/src/menu2.rs+++ b/crates/menu2/src/menu2.rs@@ -1,4 +1,9 @@-use gpui::actions;+use gpui::{actions, ctor};++// todo!(remove this)+// https://github.com/rust-lang/rust/issues/47384+// https://github.com/mmastrac/rust-ctor/issues/280+pub fn unused() {}actions!(Cancel,diff --git a/crates/workspace2/src/modal_layer.rs b/crates/workspace2/src/modal_layer.rsindex 694b4e7ffe1..55edab353be 100644--- a/crates/workspace2/src/modal_layer.rs+++ b/crates/workspace2/src/modal_layer.rs@@ -1,7 +1,7 @@use crate::Workspace;use gpui::{div, px, AnyView, AppContext, Component, Div, ParentElement, Render, StatelessInteractive,- Styled, View, ViewContext,+ Styled, View, ViewContext, EventEmitter,};use std::{any::TypeId, sync::Arc};use ui::v_stack;@@ -27,10 +27,18 @@ struct ToggleModal {name: String,}+pub enum ModalEvents {+ Dismissed+}++trait Modal: EventEmitter + Render {+ fn to_modal_events(&Self::Event) -> Option<ModalEvents>;+}+impl ModalRegistry {pub fn register_modal<A: 'static, V, B>(&mut self, action: A, build_view: B)where- V: Render,+ V: Modal,B: Fn(&Workspace, &mut ViewContext<Workspace>) -> Option<View<V>> + 'static,{let build_view = Arc::new(build_view);@@ -45,10 +53,15 @@ impl ModalRegistry {let Some(new_modal) = (build_view)(workspace, cx) else {return;};-workspace.modal_layer.update(cx, |modal_layer, _| {modal_layer.open_modal = Some(new_modal.into());});+ cx.subscribe(new_modal, |e, modal, cx| {+ match modal.to_modal_events(e) {+ Some(Dismissed) =>+ dismissed -> whatever+ }+ })cx.notify();},diff --git a/crates/zed2/Cargo.toml b/crates/zed2/Cargo.tomlindex 2c93de734e9..f7cb69c73a8 100644--- a/crates/zed2/Cargo.toml+++ b/crates/zed2/Cargo.toml@@ -48,6 +48,7 @@ journal = { package = "journal2", path = "../journal2" }language = { package = "language2", path = "../language2" }# language_selector = { path = "../language_selector" }lsp = { package = "lsp2", path = "../lsp2" }+menu = { package = "menu2", path = "../menu2" }language_tools = { path = "../language_tools" }node_runtime = { path = "../node_runtime" }# assistant = { path = "../assistant" }diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rsindex 7f25a6a5d4f..cd0f8e5fbf7 100644--- a/crates/zed2/src/main.rs+++ b/crates/zed2/src/main.rs@@ -56,6 +56,10 @@ use zed2::{mod open_listener;fn main() {+ //TODO!(figure out what the linker issues are here)+ // https://github.com/rust-lang/rust/issues/47384+ // https://github.com/mmastrac/rust-ctor/issues/280+ menu::unused();let http = http::client();init_paths();init_logger();