Skip to content

Commit

Permalink
move area() out of compositor trait
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Feb 5, 2023
1 parent 5c33bc2 commit 11e97c2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
5 changes: 2 additions & 3 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4073,8 +4073,7 @@ pub fn completion(cx: &mut Context) {
let size = compositor.size();
let signature_help_area = compositor
.find_id::<Popup<SignatureHelp>>(SignatureHelp::ID)
.and_then(|signature_help| signature_help.area(size, editor))
.unwrap();
.map(|signature_help| signature_help.area(size, editor));
let ui = compositor.find::<ui::EditorView>().unwrap();

// Delete the signature help popup if they intersect.
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rect> {
None
}
}

pub struct Compositor {
Expand Down
8 changes: 4 additions & 4 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -484,8 +488,4 @@ impl Component for Completion {
markdown_doc.render(area, surface, cx);
}
}

fn area(&mut self, viewport: Rect, editor: &Editor) -> Option<Rect> {
self.popup.area(viewport, editor)
}
}
3 changes: 1 addition & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,6 @@ impl EditorView {
}
}

#[allow(clippy::too_many_arguments)]
pub fn set_completion(
&mut self,
editor: &mut Editor,
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 12 additions & 12 deletions helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ impl<T: Component> Popup<T> {
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<T: Component> Component for Popup<T> {
Expand Down Expand Up @@ -235,7 +246,7 @@ impl<T: Component> Component for Popup<T> {
}

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
Expand Down Expand Up @@ -283,15 +294,4 @@ impl<T: Component> Component for Popup<T> {
fn id(&self) -> Option<&'static str> {
Some(self.id)
}

fn area(&mut self, viewport: Rect, editor: &Editor) -> Option<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));
Some(area)
}
}

0 comments on commit 11e97c2

Please sign in to comment.