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 element-types
Conrad Irwin5dda10518269
diff --cc crates/editor2/src/element.rsindex 3efd399a518,638ed338919..d06f73c92b4--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@@ -15,12 -18,11 +18,11 @@@ use crate::use anyhow::Result;use collections::{BTreeMap, HashMap};use gpui::{- black, hsla, point, px, relative, size, transparent_black, Action, AnyElement, AvailableSpace,- BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchPhase, Edges, Element,- ElementId, ElementInputHandler, Entity, FocusHandle, GlobalElementId, Hsla, InputHandler,- KeyContext, KeyDownEvent, KeyMatch, Line, LineLayout, Modifiers, MouseButton, MouseDownEvent,- MouseMoveEvent, MouseUpEvent, Pixels, ScrollWheelEvent, ShapedGlyph, Size, Style, TextRun,- TextStyle, TextSystem, ViewContext, WindowContext, WrappedLineLayout,+ point, px, relative, size, transparent_black, Action, AnyElement, AvailableSpace, BorrowWindow,+ Bounds, Component, ContentMask, Corners, DispatchPhase, Edges, Element, ElementId,+ ElementInputHandler, Entity, Hsla, Line, MouseButton, MouseDownEvent, MouseMoveEvent,- MouseUpEvent, ParentElement, Pixels, ScrollWheelEvent, Size, Style, Styled, TextRun, TextStyle,- ViewContext, WindowContext,++ MouseUpEvent, ParentComponent, Pixels, ScrollWheelEvent, Size, Style, Styled, TextRun,++ TextStyle, ViewContext, WindowContext,};use itertools::Itertools;use language::language_settings::ShowWhitespaceSetting;@@@ -2656,28 -2583,70 +2618,33 @@@ impl Element<Editor> for EditorElementregister_action(cx, Editor::context_menu_prev);register_action(cx, Editor::context_menu_next);register_action(cx, Editor::context_menu_last);- },- )- });- }-- fn layout(- &mut self,- editor: &mut Editor,- element_state: &mut Self::ElementState,- cx: &mut gpui::ViewContext<Editor>,- ) -> gpui::LayoutId {- let rem_size = cx.rem_size();- let mut style = Style::default();- style.size.width = relative(1.).into();- style.size.height = match editor.mode {- EditorMode::SingleLine => self.style.text.line_height_in_pixels(cx.rem_size()).into(),- EditorMode::AutoHeight { .. } => todo!(),- EditorMode::Full => relative(1.).into(),- };- cx.request_layout(&style, None)- }- fn paint(- &mut self,- bounds: Bounds<gpui::Pixels>,- editor: &mut Editor,- element_state: &mut Self::ElementState,- cx: &mut gpui::ViewContext<Editor>,- ) {- let mut layout = self.compute_layout(editor, cx, bounds);- let gutter_bounds = Bounds {- origin: bounds.origin,- size: layout.gutter_size,- };- let text_bounds = Bounds {- origin: gutter_bounds.upper_right(),- size: layout.text_size,- };-- // We call with_z_index to establish a new stacking context.- cx.with_z_index(0, |cx| {- cx.with_content_mask(ContentMask { bounds }, |cx| {- self.paint_mouse_listeners(- bounds,- gutter_bounds,- text_bounds,- &layout.position_map,- cx,- );-- self.paint_background(gutter_bounds, text_bounds, &layout, cx);- if layout.gutter_size.width > Pixels::ZERO {- self.paint_gutter(gutter_bounds, &mut layout, editor, cx);- }-- self.paint_text(text_bounds, &mut layout, editor, cx);+ // We call with_z_index to establish a new stacking context.+ cx.with_z_index(0, |cx| {+ cx.with_content_mask(Some(ContentMask { bounds }), |cx| {+ self.paint_mouse_listeners(+ bounds,+ gutter_bounds,+ text_bounds,+ &layout.position_map,+ cx,+ );+ self.paint_background(gutter_bounds, text_bounds, &layout, cx);+ if layout.gutter_size.width > Pixels::ZERO {+ self.paint_gutter(gutter_bounds, &mut layout, editor, cx);+ }+ self.paint_text(text_bounds, &mut layout, editor, cx);+- if !layout.blocks.is_empty() {- self.paint_blocks(bounds, &mut layout, editor, cx);- }++ if !layout.blocks.is_empty() {++ self.paint_blocks(bounds, &mut layout, editor, cx);++ }+- let input_handler = ElementInputHandler::new(bounds, cx);- cx.handle_input(&editor.focus_handle, input_handler);- });+ let input_handler = ElementInputHandler::new(bounds, cx);+ cx.handle_input(&editor.focus_handle, input_handler);+ });+ });+ },- );++ )});}}diff --cc crates/project_panel2/src/project_panel.rsindex e3e04f5254f,1feead1a19e..41778c0cb5d--- a/crates/project_panel2/src/project_panel.rs+++ b/crates/project_panel2/src/project_panel.rs@@@ -8,11 -8,11 +8,11 @@@ use file_associations::FileAssociationsuse anyhow::{anyhow, Result};use gpui::{- actions, div, px, svg, uniform_list, Action, AppContext, AssetSource, AsyncAppContext,- AsyncWindowContext, ClipboardItem, Div, Element, Entity, EventEmitter, FocusEnabled,- FocusHandle, Model, ParentElement as _, Pixels, Point, PromptLevel, Render,- StatefulInteractive, StatefulInteractivity, Styled, Task, UniformListScrollHandle, View,- ViewContext, VisualContext as _, WeakView, WindowContext,+ actions, div, px, rems, svg, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext,- ClipboardItem, Component, Div, EventEmitter, FocusHandle, FocusableKeyDispatch, Model,- MouseButton, ParentElement as _, Pixels, Point, PromptLevel, Render, StatefulInteractive,- StatefulInteractivity, StatelessInteractive, Styled, Task, UniformListScrollHandle, View,- ViewContext, VisualContext as _, WeakView, WindowContext,++ ClipboardItem, Component, Div, EventEmitter, FocusHandle, Focusable, InteractiveComponent,++ Model, MouseButton, ParentComponent, Pixels, Point, PromptLevel, Render, Stateful,++ StatefulInteractiveComponent, Styled, Task, UniformListScrollHandle, View, ViewContext,++ VisualContext as _, WeakView, WindowContext,};use menu::{Confirm, SelectNext, SelectPrev};use project::{@@@ -1390,13 -1378,12 +1378,12 @@@ impl ProjectPanel}fn render_entry(+ &self,entry_id: ProjectEntryId,details: EntryDetails,- editor: &View<Editor>,// dragged_entry_destination: &mut Option<Arc<Path>>,- // theme: &theme::ProjectPanel,cx: &mut ViewContext<Self>,-- ) -> Div<Self, StatefulInteractivity<Self>> {++ ) -> Stateful<Self, Div<Self>> {let kind = details.kind;let settings = ProjectPanelSettings::get_global(cx);const INDENT_SIZE: Pixels = px(16.0);@@@ -1438,18 -1429,36 +1429,36 @@@}impl Render for ProjectPanel {- type Element = Div<Self, StatefulInteractivity<Self>, FocusEnabled<Self>>;-- fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {- enum ProjectPanel {}- let theme = cx.theme();- let last_worktree_root_id = self.last_worktree_root_id;- type Element = Div<Self, StatefulInteractivity<Self>, FocusableKeyDispatch<Self>>;++ type Element = Focusable<Self, Stateful<Self, Div<Self>>>;+ fn render(&mut self, _cx: &mut gpui::ViewContext<Self>) -> Self::Element {let has_worktree = self.visible_entries.len() != 0;if has_worktree {div().id("project-panel")+ .size_full()- .context("ProjectPanel")++ .key_context("ProjectPanel")+ .on_action(Self::select_next)+ .on_action(Self::select_prev)+ .on_action(Self::expand_selected_entry)+ .on_action(Self::collapse_selected_entry)+ .on_action(Self::collapse_all_entries)+ .on_action(Self::new_file)+ .on_action(Self::new_directory)+ .on_action(Self::rename)+ .on_action(Self::delete)+ .on_action(Self::confirm)+ .on_action(Self::open_file)+ .on_action(Self::cancel)+ .on_action(Self::cut)+ .on_action(Self::copy)+ .on_action(Self::copy_path)+ .on_action(Self::copy_relative_path)+ .on_action(Self::paste)+ .on_action(Self::reveal_in_finder)+ .on_action(Self::open_in_terminal)+ .on_action(Self::new_search_in_directory).track_focus(&self.focus_handle).child(uniform_list(diff --cc crates/ui2/src/components/icon_button.rsindex 86803c584c9,b20cd310361..c9982f1f671--- a/crates/ui2/src/components/icon_button.rs+++ b/crates/ui2/src/components/icon_button.rs@@@ -1,6 -1,5 +1,6 @@@-use crate::{h_stack, prelude::*, ClickHandler, Icon, IconColor, IconElement, TextTooltip};-use gpui::{MouseButton, VisualContext};+use crate::{h_stack, prelude::*};- use crate::{ClickHandler, Icon, IconColor, IconElement};- use gpui::{prelude::*, rems, MouseButton};++use crate::{ClickHandler, Icon, IconColor, IconElement, TextTooltip};++use gpui::{prelude::*, MouseButton, VisualContext};use std::sync::Arc;struct IconButtonHandlers<V: 'static> {diff --cc crates/workspace2/src/dock.rsindex 499fb0d673b,9a614bc92ee..7c732e8f48a--- a/crates/workspace2/src/dock.rs+++ b/crates/workspace2/src/dock.rs@@@ -1,7 -1,7 +1,7 @@@use crate::{status_bar::StatusItemView, Axis, Workspace};use gpui::{- div, Action, AnyView, AppContext, Div, Entity, EntityId, EventEmitter, ParentComponent, Render,- Subscription, View, ViewContext, WeakView, WindowContext,+ div, Action, AnyView, AppContext, Div, Entity, EntityId, EventEmitter, FocusHandle,- ParentElement, Render, Styled, Subscription, View, ViewContext, WeakView, WindowContext,++ ParentComponent, Render, Styled, Subscription, View, ViewContext, WeakView, WindowContext,};use schemars::JsonSchema;use serde::{Deserialize, Serialize};diff --cc crates/workspace2/src/pane.rsindex de078475839,e3ea4863c99..5dc6b8b6920--- a/crates/workspace2/src/pane.rs+++ b/crates/workspace2/src/pane.rs@@@ -1917,7 -1919,12 +1917,12 @@@ impl Render for Panefn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {v_stack()- .context("Pane")++ .key_context("Pane").size_full()+ .on_action(|pane: &mut Self, action, cx| {+ pane.close_active_item(action, cx)+ .map(|task| task.detach_and_log_err(cx));+ }).child(self.render_tab_bar(cx)).child(div() /* todo!(toolbar) */).child(if let Some(item) = self.active_item() {diff --cc crates/workspace2/src/workspace2.rsindex 3e3312ac3a6,f938dcaa45a..bba86b6beb2--- a/crates/workspace2/src/workspace2.rs+++ b/crates/workspace2/src/workspace2.rs@@@ -3443,8 -3279,110 +3271,109 @@@ impl Workspace})}+ fn actions(div: Div<Self>) -> Div<Self> {+ div+ // cx.add_async_action(Workspace::open);+ // cx.add_async_action(Workspace::follow_next_collaborator);+ // cx.add_async_action(Workspace::close);+ // cx.add_async_action(Workspace::close_inactive_items_and_panes);+ // cx.add_async_action(Workspace::close_all_items_and_panes);+ // cx.add_global_action(Workspace::close_global);+ // cx.add_global_action(restart);+ // cx.add_async_action(Workspace::save_all);+ // cx.add_action(Workspace::add_folder_to_project);+ // cx.add_action(+ // |workspace: &mut Workspace, _: &Unfollow, cx: &mut ViewContext<Workspace>| {+ // let pane = workspace.active_pane().clone();+ // workspace.unfollow(&pane, cx);+ // },+ // );+ // cx.add_action(+ // |workspace: &mut Workspace, action: &Save, cx: &mut ViewContext<Workspace>| {+ // workspace+ // .save_active_item(action.save_intent.unwrap_or(SaveIntent::Save), cx)+ // .detach_and_log_err(cx);+ // },+ // );+ // cx.add_action(+ // |workspace: &mut Workspace, _: &SaveAs, cx: &mut ViewContext<Workspace>| {+ // workspace+ // .save_active_item(SaveIntent::SaveAs, cx)+ // .detach_and_log_err(cx);+ // },+ // );+ // cx.add_action(|workspace: &mut Workspace, _: &ActivatePreviousPane, cx| {+ // workspace.activate_previous_pane(cx)+ // });+ // cx.add_action(|workspace: &mut Workspace, _: &ActivateNextPane, cx| {+ // workspace.activate_next_pane(cx)+ // });+ // cx.add_action(+ // |workspace: &mut Workspace, action: &ActivatePaneInDirection, cx| {+ // workspace.activate_pane_in_direction(action.0, cx)+ // },+ // );+ // cx.add_action(+ // |workspace: &mut Workspace, action: &SwapPaneInDirection, cx| {+ // workspace.swap_pane_in_direction(action.0, cx)+ // },+ // );+ .on_action(|this, e: &ToggleLeftDock, cx| {+ println!("TOGGLING DOCK");+ this.toggle_dock(DockPosition::Left, cx);+ })+ // cx.add_action(|workspace: &mut Workspace, _: &ToggleRightDock, cx| {+ // workspace.toggle_dock(DockPosition::Right, cx);+ // });+ // cx.add_action(|workspace: &mut Workspace, _: &ToggleBottomDock, cx| {+ // workspace.toggle_dock(DockPosition::Bottom, cx);+ // });+ // cx.add_action(|workspace: &mut Workspace, _: &CloseAllDocks, cx| {+ // workspace.close_all_docks(cx);+ // });+ // cx.add_action(Workspace::activate_pane_at_index);+ // cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| {+ // workspace.reopen_closed_item(cx).detach();+ // });+ // cx.add_action(|workspace: &mut Workspace, _: &GoBack, cx| {+ // workspace+ // .go_back(workspace.active_pane().downgrade(), cx)+ // .detach();+ // });+ // cx.add_action(|workspace: &mut Workspace, _: &GoForward, cx| {+ // workspace+ // .go_forward(workspace.active_pane().downgrade(), cx)+ // .detach();+ // });++ // cx.add_action(|_: &mut Workspace, _: &install_cli::Install, cx| {+ // cx.spawn(|workspace, mut cx| async move {+ // let err = install_cli::install_cli(&cx)+ // .await+ // .context("Failed to create CLI symlink");++ // workspace.update(&mut cx, |workspace, cx| {+ // if matches!(err, Err(_)) {+ // err.notify_err(workspace, cx);+ // } else {+ // workspace.show_notification(1, cx, |cx| {+ // cx.build_view(|_| {+ // MessageNotification::new("Successfully installed the `zed` binary")+ // })+ // });+ // }+ // })+ // })+ // .detach();+ // });+ }++ // todo!()+ // #[cfg(any(test, feature = "test-support"))]+ // pub fn test_new(project: ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {+ // use node_runtime::FakeNodeRuntime;#[cfg(any(test, feature = "test-support"))]pub fn test_new(project: Model<Project>, cx: &mut ViewContext<Self>) -> Self {- use gpui::Context;use node_runtime::FakeNodeRuntime;let client = project.read(cx).client();