Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge remote-tracking branch 'origin/main' into editor2

Antonio Scandurra097171b9b832
diff --cc crates/workspace2/src/item.rs
index c3013595e6d,15b387cbed4..e933f373d4a
--- a/crates/workspace2/src/item.rs
+++ b/crates/workspace2/src/item.rs
@@@ -11,10 -11,11 +11,10 @@@ use client2::
proto::{self, PeerId},
Client,
};
- use gpui2::{
+ use gpui::{
- AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, HighlightStyle, Model, Pixels,
- Point, Render, SharedString, Task, View, ViewContext, WeakView, WindowContext,
+ AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, HighlightStyle,
+ Model, Pixels, Point, Render, SharedString, Task, View, ViewContext, WeakView, WindowContext,
};
-use parking_lot::Mutex;
use project2::{Project, ProjectEntryId, ProjectPath};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@@ -264,10 -253,10 +264,10 @@@ pub trait ItemHandle: 'static + Send
fn act_as_type(&self, type_id: TypeId, cx: &AppContext) -> Option<AnyView>;
fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>>;
fn on_release(
- &mut self,
+ &self,
cx: &mut AppContext,
callback: Box<dyn FnOnce(&mut AppContext) + Send>,
- ) -> gpui2::Subscription;
+ ) -> gpui::Subscription;
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
fn breadcrumbs(&self, theme: &ThemeVariant, cx: &AppContext) -> Option<Vec<BreadcrumbText>>;
@@@ -588,10 -570,10 +588,10 @@@ impl<T: Item> ItemHandle for View<T>
}
fn on_release(
- &mut self,
+ &self,
cx: &mut AppContext,
callback: Box<dyn FnOnce(&mut AppContext) + Send>,
- ) -> gpui2::Subscription {
+ ) -> gpui::Subscription {
cx.observe_release(self, move |_, cx| callback(cx))
}
diff --cc crates/workspace2/src/pane.rs
index f940108c5a1,16dbfda3612..acc41deba88
--- a/crates/workspace2/src/pane.rs
+++ b/crates/workspace2/src/pane.rs
@@@ -8,9 -8,9 +8,9 @@@ use crate::
};
use anyhow::Result;
use collections::{HashMap, HashSet, VecDeque};
- use gpui2::{
+ use gpui::{
- AppContext, AsyncWindowContext, Component, Div, EntityId, EventEmitter, Model, PromptLevel,
- Render, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
+ AppContext, AsyncWindowContext, Component, Div, EntityId, EventEmitter, FocusHandle, Model,
+ PromptLevel, Render, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
};
use parking_lot::Mutex;
use project2::{Project, ProjectEntryId, ProjectPath};
@@@ -416,17 -416,17 +416,17 @@@ impl Pane
}
}
- // pub(crate) fn workspace(&self) -> &WeakView<Workspace> {
- // &self.workspace
- // }
+ pub(crate) fn workspace(&self) -> &WeakView<Workspace> {
+ &self.workspace
+ }
- pub fn has_focus(&self) -> bool {
- self.has_focus
+ pub fn has_focus(&self, cx: &WindowContext) -> bool {
+ self.focus_handle.contains_focused(cx)
}
- // pub fn active_item_index(&self) -> usize {
- // self.active_item_index
- // }
+ pub fn active_item_index(&self) -> usize {
+ self.active_item_index
+ }
// pub fn on_can_drop<F>(&mut self, can_drop: F)
// where
diff --cc crates/workspace2/src/workspace2.rs
index 2d0ca4529f0,bb9cb7e527e..f7e9a0d5854
--- a/crates/workspace2/src/workspace2.rs
+++ b/crates/workspace2/src/workspace2.rs
@@@ -33,14 -31,15 +34,15 @@@ use futures::
future::try_join_all,
Future, FutureExt, StreamExt,
};
- use gpui2::{
+ use gpui::{
div, point, size, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext,
- AsyncWindowContext, Bounds, Component, Div, EntityId, EventEmitter, GlobalPixels, Model,
- ModelContext, ParentElement, Point, Render, Size, StatefulInteractive, Styled, Subscription,
- Task, View, ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle,
- WindowOptions,
+ AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, EventEmitter, FocusHandle,
+ GlobalPixels, Model, ModelContext, ParentElement, Point, Render, Size, StatefulInteractive,
+ Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowBounds,
+ WindowContext, WindowHandle, WindowOptions,
};
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
+ use itertools::Itertools;
use language2::LanguageRegistry;
use lazy_static::lazy_static;
use node_runtime::NodeRuntime;
@@@ -1925,61 -1924,60 +1926,60 @@@ impl Workspace
// self.zoomed.and_then(|view| view.upgrade(cx))
// }
- // fn dismiss_zoomed_items_to_reveal(
- // &mut self,
- // dock_to_reveal: Option<DockPosition>,
- // cx: &mut ViewContext<Self>,
- // ) {
- // // If a center pane is zoomed, unzoom it.
- // for pane in &self.panes {
- // if pane != &self.active_pane || dock_to_reveal.is_some() {
- // pane.update(cx, |pane, cx| pane.set_zoomed(false, cx));
- // }
- // }
+ fn dismiss_zoomed_items_to_reveal(
+ &mut self,
+ dock_to_reveal: Option<DockPosition>,
+ cx: &mut ViewContext<Self>,
+ ) {
+ // If a center pane is zoomed, unzoom it.
+ for pane in &self.panes {
+ if pane != &self.active_pane || dock_to_reveal.is_some() {
+ pane.update(cx, |pane, cx| pane.set_zoomed(false, cx));
+ }
+ }
- // // If another dock is zoomed, hide it.
- // let mut focus_center = false;
- // for dock in [&self.left_dock, &self.right_dock, &self.bottom_dock] {
- // dock.update(cx, |dock, cx| {
- // if Some(dock.position()) != dock_to_reveal {
- // if let Some(panel) = dock.active_panel() {
- // if panel.is_zoomed(cx) {
- // focus_center |= panel.has_focus(cx);
- // dock.set_open(false, cx);
- // }
- // }
- // }
- // });
- // }
+ // If another dock is zoomed, hide it.
+ let mut focus_center = false;
+ for dock in [&self.left_dock, &self.right_dock, &self.bottom_dock] {
+ dock.update(cx, |dock, cx| {
+ if Some(dock.position()) != dock_to_reveal {
+ if let Some(panel) = dock.active_panel() {
+ if panel.is_zoomed(cx) {
+ focus_center |= panel.has_focus(cx);
+ dock.set_open(false, cx);
+ }
+ }
+ }
+ });
+ }
- // if focus_center {
- // cx.focus_self();
- // }
+ if focus_center {
+ cx.focus(&self.focus_handle);
+ }
- // if self.zoomed_position != dock_to_reveal {
- // self.zoomed = None;
- // self.zoomed_position = None;
- // }
+ if self.zoomed_position != dock_to_reveal {
+ self.zoomed = None;
+ self.zoomed_position = None;
+ }
- // cx.notify();
- // }
+ cx.notify();
+ }
- fn add_pane(&mut self, _cx: &mut ViewContext<Self>) -> View<Pane> {
- todo!()
- // let pane = cx.build_view(|cx| {
- // Pane::new(
- // self.weak_handle(),
- // self.project.clone(),
- // self.pane_history_timestamp.clone(),
- // cx,
- // )
- // });
- // cx.subscribe(&pane, Self::handle_pane_event).detach();
- // self.panes.push(pane.clone());
+ fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> View<Pane> {
+ let pane = cx.build_view(|cx| {
+ Pane::new(
+ self.weak_handle(),
+ self.project.clone(),
+ self.pane_history_timestamp.clone(),
+ cx,
+ )
+ });
+ cx.subscribe(&pane, Self::handle_pane_event).detach();
+ self.panes.push(pane.clone());
// todo!()
// cx.focus(&pane);
- // cx.emit(Event::PaneAdded(pane.clone()));
- // pane
+ cx.emit(Event::PaneAdded(pane.clone()));
+ pane
}
// pub fn add_item_to_center(
diff --cc crates/zed2/src/zed2.rs
index e3b54e6e62c,a33498538e7..7368d3a5efe
--- a/crates/zed2/src/zed2.rs
+++ b/crates/zed2/src/zed2.rs
@@@ -58,35 -257,35 +58,35 @@@ pub fn initialize_workspace
let workspace_handle = cx.view();
cx.subscribe(&workspace_handle, {
move |workspace, _, event, cx| {
- if let workspace2::Event::PaneAdded(pane) = event {
+ if let workspace::Event::PaneAdded(pane) = event {
pane.update(cx, |pane, cx| {
- // todo!()
- // pane.toolbar().update(cx, |toolbar, cx| {
- // let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace));
- // toolbar.add_item(breadcrumbs, cx);
- // let buffer_search_bar = cx.add_view(BufferSearchBar::new);
- // toolbar.add_item(buffer_search_bar.clone(), cx);
- // let quick_action_bar = cx.add_view(|_| {
- // QuickActionBar::new(buffer_search_bar, workspace)
- // });
- // toolbar.add_item(quick_action_bar, cx);
- // let diagnostic_editor_controls =
- // cx.add_view(|_| diagnostics2::ToolbarControls::new());
- // toolbar.add_item(diagnostic_editor_controls, cx);
- // let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
- // toolbar.add_item(project_search_bar, cx);
- // let submit_feedback_button =
- // cx.add_view(|_| SubmitFeedbackButton::new());
- // toolbar.add_item(submit_feedback_button, cx);
- // let feedback_info_text = cx.add_view(|_| FeedbackInfoText::new());
- // toolbar.add_item(feedback_info_text, cx);
- // let lsp_log_item =
- // cx.add_view(|_| language_tools::LspLogToolbarItemView::new());
- // toolbar.add_item(lsp_log_item, cx);
- // let syntax_tree_item = cx
- // .add_view(|_| language_tools::SyntaxTreeToolbarItemView::new());
- // toolbar.add_item(syntax_tree_item, cx);
- // })
+ pane.toolbar().update(cx, |toolbar, cx| {
+ // todo!()
+ // let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace));
+ // toolbar.add_item(breadcrumbs, cx);
+ // let buffer_search_bar = cx.add_view(BufferSearchBar::new);
+ // toolbar.add_item(buffer_search_bar.clone(), cx);
+ // let quick_action_bar = cx.add_view(|_| {
+ // QuickActionBar::new(buffer_search_bar, workspace)
+ // });
+ // toolbar.add_item(quick_action_bar, cx);
+ // let diagnostic_editor_controls =
+ // cx.add_view(|_| diagnostics2::ToolbarControls::new());
+ // toolbar.add_item(diagnostic_editor_controls, cx);
+ // let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
+ // toolbar.add_item(project_search_bar, cx);
+ // let submit_feedback_button =
+ // cx.add_view(|_| SubmitFeedbackButton::new());
+ // toolbar.add_item(submit_feedback_button, cx);
+ // let feedback_info_text = cx.add_view(|_| FeedbackInfoText::new());
+ // toolbar.add_item(feedback_info_text, cx);
+ // let lsp_log_item =
+ // cx.add_view(|_| language_tools::LspLogToolbarItemView::new());
+ // toolbar.add_item(lsp_log_item, cx);
+ // let syntax_tree_item = cx
+ // .add_view(|_| language_tools::SyntaxTreeToolbarItemView::new());
+ // toolbar.add_item(syntax_tree_item, cx);
+ })
});
}
}