Implement following and more collaboration panel features in zed2 (#3504)

This commit is contained in:
Max Brunsfeld 2023-12-05 13:59:15 -08:00 committed by GitHub
commit 5b6fd3ac1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 189 additions and 304 deletions

View file

@ -35,7 +35,7 @@ use theme::{ActiveTheme, Theme};
use ui::{h_stack, Color, Label};
use util::{paths::PathExt, paths::FILE_ROW_COLUMN_DELIMITER, ResultExt, TryFutureExt};
use workspace::{
item::{BreadcrumbText, FollowEvent, FollowableEvents, FollowableItemHandle},
item::{BreadcrumbText, FollowEvent, FollowableItemHandle},
StatusItemView,
};
use workspace::{
@ -46,27 +46,7 @@ use workspace::{
pub const MAX_TAB_TITLE_LEN: usize = 24;
impl FollowableEvents for EditorEvent {
fn to_follow_event(&self) -> Option<workspace::item::FollowEvent> {
match self {
EditorEvent::Edited => Some(FollowEvent::Unfollow),
EditorEvent::SelectionsChanged { local }
| EditorEvent::ScrollPositionChanged { local, .. } => {
if *local {
Some(FollowEvent::Unfollow)
} else {
None
}
}
_ => None,
}
}
}
impl EventEmitter<ItemEvent> for Editor {}
impl FollowableItem for Editor {
type FollowableEvent = EditorEvent;
fn remote_id(&self) -> Option<ViewId> {
self.remote_id
}
@ -241,9 +221,24 @@ impl FollowableItem for Editor {
}))
}
fn to_follow_event(event: &EditorEvent) -> Option<workspace::item::FollowEvent> {
match event {
EditorEvent::Edited => Some(FollowEvent::Unfollow),
EditorEvent::SelectionsChanged { local }
| EditorEvent::ScrollPositionChanged { local, .. } => {
if *local {
Some(FollowEvent::Unfollow)
} else {
None
}
}
_ => None,
}
}
fn add_event_to_update_proto(
&self,
event: &Self::FollowableEvent,
event: &EditorEvent,
update: &mut Option<proto::update_view::Variant>,
cx: &WindowContext,
) -> bool {
@ -528,6 +523,8 @@ fn deserialize_anchor(buffer: &MultiBufferSnapshot, anchor: proto::EditorAnchor)
}
impl Item for Editor {
type Event = EditorEvent;
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
if let Ok(data) = data.downcast::<NavigationData>() {
let newest_selection = self.selections.newest::<Point>(cx);
@ -838,6 +835,40 @@ impl Item for Editor {
Some("Editor")
}
fn to_item_events(event: &EditorEvent, mut f: impl FnMut(ItemEvent)) {
match event {
EditorEvent::Closed => f(ItemEvent::CloseItem),
EditorEvent::Saved | EditorEvent::TitleChanged => {
f(ItemEvent::UpdateTab);
f(ItemEvent::UpdateBreadcrumbs);
}
EditorEvent::Reparsed => {
f(ItemEvent::UpdateBreadcrumbs);
}
EditorEvent::SelectionsChanged { local } if *local => {
f(ItemEvent::UpdateBreadcrumbs);
}
EditorEvent::DirtyChanged => {
f(ItemEvent::UpdateTab);
}
EditorEvent::BufferEdited => {
f(ItemEvent::Edit);
f(ItemEvent::UpdateBreadcrumbs);
}
EditorEvent::ExcerptsAdded { .. } | EditorEvent::ExcerptsRemoved { .. } => {
f(ItemEvent::Edit);
}
_ => {}
}
}
fn deserialize(
project: Model<Project>,
_workspace: WeakView<Workspace>,