From 3329b2bbd6994a4fcd47b29d950c591b07a48c16 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Tue, 24 Jan 2023 19:46:04 -0500 Subject: [PATCH 1/4] Remove `gpui::` prefix from parameters --- crates/feedback/src/feedback_editor.rs | 32 +++++++++----------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/crates/feedback/src/feedback_editor.rs b/crates/feedback/src/feedback_editor.rs index b3322f50db..3a6bc744f2 100644 --- a/crates/feedback/src/feedback_editor.rs +++ b/crates/feedback/src/feedback_editor.rs @@ -12,7 +12,7 @@ use gpui::{ elements::{ChildView, Flex, Label, MouseEventHandler, ParentElement, Stack, Text}, serde_json, AnyViewHandle, AppContext, CursorStyle, Element, ElementBox, Entity, ModelHandle, MouseButton, MutableAppContext, PromptLevel, RenderContext, Task, View, ViewContext, - ViewHandle, + ViewHandle, WeakViewHandle, }; use isahc::Request; use language::Buffer; @@ -79,12 +79,7 @@ impl View for FeedbackButton { } impl StatusItemView for FeedbackButton { - fn set_active_pane_item( - &mut self, - _: Option<&dyn ItemHandle>, - _: &mut gpui::ViewContext, - ) { - } + fn set_active_pane_item(&mut self, _: Option<&dyn ItemHandle>, _: &mut ViewContext) {} } #[derive(Serialize)] @@ -135,7 +130,7 @@ impl FeedbackEditor { fn handle_save( &mut self, - _: gpui::ModelHandle, + _: ModelHandle, cx: &mut ViewContext, ) -> Task> { let feedback_char_count = self.editor.read(cx).buffer().read(cx).len(cx); @@ -269,12 +264,7 @@ impl Entity for FeedbackEditor { } impl Item for FeedbackEditor { - fn tab_content( - &self, - _: Option, - style: &theme::Tab, - _: &gpui::AppContext, - ) -> ElementBox { + fn tab_content(&self, _: Option, style: &theme::Tab, _: &AppContext) -> ElementBox { Flex::row() .with_child( Label::new("Feedback".to_string(), style.label.clone()) @@ -293,19 +283,19 @@ impl Item for FeedbackEditor { Vec::new() } - fn is_singleton(&self, _: &gpui::AppContext) -> bool { + fn is_singleton(&self, _: &AppContext) -> bool { true } fn set_nav_history(&mut self, _: workspace::ItemNavHistory, _: &mut ViewContext) {} - fn can_save(&self, _: &gpui::AppContext) -> bool { + fn can_save(&self, _: &AppContext) -> bool { true } fn save( &mut self, - project: gpui::ModelHandle, + project: ModelHandle, cx: &mut ViewContext, ) -> Task> { self.handle_save(project, cx) @@ -313,7 +303,7 @@ impl Item for FeedbackEditor { fn save_as( &mut self, - project: gpui::ModelHandle, + project: ModelHandle, _: std::path::PathBuf, cx: &mut ViewContext, ) -> Task> { @@ -322,7 +312,7 @@ impl Item for FeedbackEditor { fn reload( &mut self, - _: gpui::ModelHandle, + _: ModelHandle, _: &mut ViewContext, ) -> Task> { unreachable!("reload should not have been called") @@ -356,8 +346,8 @@ impl Item for FeedbackEditor { } fn deserialize( - _: gpui::ModelHandle, - _: gpui::WeakViewHandle, + _: ModelHandle, + _: WeakViewHandle, _: workspace::WorkspaceId, _: workspace::ItemId, _: &mut ViewContext, From f68f9f37ab61cdccdc93be044e0c375a63cec50a Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Wed, 25 Jan 2023 14:20:23 -0500 Subject: [PATCH 2/4] Add cursor position to feedback editor Co-Authored-By: Mikayla Maki Co-Authored-By: Max Brunsfeld --- crates/editor/src/items.rs | 2 +- crates/feedback/src/feedback_editor.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 7e7f44e514..501306aa19 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -1094,7 +1094,7 @@ impl StatusItemView for CursorPosition { active_pane_item: Option<&dyn ItemHandle>, cx: &mut ViewContext, ) { - if let Some(editor) = active_pane_item.and_then(|item| item.downcast::()) { + if let Some(editor) = active_pane_item.and_then(|item| item.act_as::(cx)) { self._observe_active_editor = Some(cx.observe(&editor, Self::update_position)); self.update_position(editor, cx); } else { diff --git a/crates/feedback/src/feedback_editor.rs b/crates/feedback/src/feedback_editor.rs index 3a6bc744f2..a3318d3efe 100644 --- a/crates/feedback/src/feedback_editor.rs +++ b/crates/feedback/src/feedback_editor.rs @@ -1,4 +1,5 @@ use std::{ + any::TypeId, ops::{Range, RangeInclusive}, sync::Arc, }; @@ -358,6 +359,21 @@ impl Item for FeedbackEditor { fn as_searchable(&self, handle: &ViewHandle) -> Option> { Some(Box::new(handle.clone())) } + + fn act_as_type( + &self, + type_id: TypeId, + self_handle: &ViewHandle, + _: &AppContext, + ) -> Option { + if type_id == TypeId::of::() { + Some(self_handle.into()) + } else if type_id == TypeId::of::() { + Some((&self.editor).into()) + } else { + None + } + } } impl SearchableItem for FeedbackEditor { From 7f3d9379380e621e825d35bd9d419d6261386f8c Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Wed, 25 Jan 2023 14:20:40 -0500 Subject: [PATCH 3/4] Count chars --- crates/feedback/src/feedback_editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/feedback/src/feedback_editor.rs b/crates/feedback/src/feedback_editor.rs index a3318d3efe..5398a8900e 100644 --- a/crates/feedback/src/feedback_editor.rs +++ b/crates/feedback/src/feedback_editor.rs @@ -134,7 +134,7 @@ impl FeedbackEditor { _: ModelHandle, cx: &mut ViewContext, ) -> Task> { - let feedback_char_count = self.editor.read(cx).buffer().read(cx).len(cx); + let feedback_char_count = self.editor.read(cx).text(cx).chars().count(); let error = if feedback_char_count < *FEEDBACK_CHAR_LIMIT.start() { Some(format!( From 328b779185f796216c95134a57582efcf77ea06e Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Wed, 25 Jan 2023 14:20:58 -0500 Subject: [PATCH 4/4] Clean up construction of FeedbackEditor --- crates/feedback/src/feedback_editor.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/feedback/src/feedback_editor.rs b/crates/feedback/src/feedback_editor.rs index 5398a8900e..e034da7db2 100644 --- a/crates/feedback/src/feedback_editor.rs +++ b/crates/feedback/src/feedback_editor.rs @@ -113,8 +113,7 @@ impl FeedbackEditor { cx.subscribe(&editor, |_, _, e, cx| cx.emit(e.clone())) .detach(); - let this = Self { editor, project }; - this + Self { editor, project } } fn new(project: ModelHandle, cx: &mut ViewContext) -> Self {