From 11e97c20a0796709c94920979354406e515e760d Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Sat, 4 Feb 2023 20:18:54 -0500 Subject: [PATCH] move area() out of compositor trait --- helix-term/src/commands.rs | 5 ++--- helix-term/src/commands/lsp.rs | 6 +++--- helix-term/src/compositor.rs | 4 ---- helix-term/src/ui/completion.rs | 8 ++++---- helix-term/src/ui/editor.rs | 3 +-- helix-term/src/ui/popup.rs | 24 ++++++++++++------------ 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 9899c57a767f9..9ac94c67449e7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4073,8 +4073,7 @@ pub fn completion(cx: &mut Context) { let size = compositor.size(); let signature_help_area = compositor .find_id::>(SignatureHelp::ID) - .and_then(|signature_help| signature_help.area(size, editor)) - .unwrap(); + .map(|signature_help| signature_help.area(size, editor)); let ui = compositor.find::().unwrap(); // Delete the signature help popup if they intersect. @@ -4087,7 +4086,7 @@ pub fn completion(cx: &mut Context) { trigger_offset, size, ) - .filter(|area| area.intersects(signature_help_area)) + .and_then(|area| Some(area.intersects(signature_help_area?))) .is_some() { compositor.remove(SignatureHelp::ID); diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 20eb880a3d973..0ebaac09a9df4 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -13,7 +13,7 @@ use helix_core::{path, Selection}; use helix_view::{apply_transaction, document::Mode, editor::Action, theme::Style}; use crate::{ - compositor::{self, Component, Compositor}, + compositor::{self, Compositor}, ui::{ self, lsp::SignatureHelp, overlay::overlayed, DynamicPicker, FileLocation, FilePicker, Popup, PromptEvent, @@ -1143,8 +1143,8 @@ pub fn signature_help_impl(cx: &mut Context, invoked: SignatureHelpInvoked) { .unwrap() .completion .as_mut() - .and_then(|completion| completion.area(size, editor)) - .filter(|area| area.intersects(popup.area(size, editor).unwrap())) + .map(|completion| completion.area(size, editor)) + .filter(|area| area.intersects(popup.area(size, editor))) .is_some() { return; diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 6091532f4d06b..2e4a2e20e9f4a 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -71,10 +71,6 @@ pub trait Component: Any + AnyComponent { fn id(&self) -> Option<&'static str> { None } - - fn area(&mut self, _viewport: Rect, _editor: &Editor) -> Option { - None - } } pub struct Compositor { diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index e41a68c63479c..41f876f087df5 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -364,6 +364,10 @@ impl Completion { true } + + pub fn area(&mut self, viewport: Rect, editor: &Editor) -> Rect { + self.popup.area(viewport, editor) + } } impl Component for Completion { @@ -484,8 +488,4 @@ impl Component for Completion { markdown_doc.render(area, surface, cx); } } - - fn area(&mut self, viewport: Rect, editor: &Editor) -> Option { - self.popup.area(viewport, editor) - } } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index fc4fa6edf2595..5cff4324aaffa 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1055,7 +1055,6 @@ impl EditorView { } } - #[allow(clippy::too_many_arguments)] pub fn set_completion( &mut self, editor: &mut Editor, @@ -1084,7 +1083,7 @@ impl EditorView { // TODO : propagate required size on resize to completion too completion.required_size((size.width, size.height)); self.completion = Some(completion); - area + Some(area) } pub fn clear_completion(&mut self, editor: &mut Editor) { diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index a914b7aded68b..cb55f33cbc775 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -158,6 +158,17 @@ impl Popup { pub fn contents_mut(&mut self) -> &mut T { &mut self.contents } + + pub fn area(&mut self, viewport: Rect, editor: &Editor) -> Rect { + // trigger required_size so we recalculate if the child changed + self.required_size((viewport.width, viewport.height)); + + let (rel_x, rel_y) = self.get_rel_position(viewport, editor); + + // clip to viewport + let area = viewport.intersection(Rect::new(rel_x, rel_y, self.size.0, self.size.1)); + area + } } impl Component for Popup { @@ -235,7 +246,7 @@ impl Component for Popup { } fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { - let area = self.area(viewport, cx.editor).unwrap(); + let area = self.area(viewport, cx.editor); cx.scroll = Some(self.scroll); // clear area @@ -283,15 +294,4 @@ impl Component for Popup { fn id(&self) -> Option<&'static str> { Some(self.id) } - - fn area(&mut self, viewport: Rect, editor: &Editor) -> Option { - // trigger required_size so we recalculate if the child changed - self.required_size((viewport.width, viewport.height)); - - let (rel_x, rel_y) = self.get_rel_position(viewport, editor); - - // clip to viewport - let area = viewport.intersection(Rect::new(rel_x, rel_y, self.size.0, self.size.1)); - Some(area) - } }