Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signature completion overlap #5495

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ pub trait Component: Any + AnyComponent {
fn id(&self) -> Option<&'static str> {
None
}

fn area(&self) -> Option<Rect> {
None
}

/// If multiple components share the same level, then only the most recent one is rendered.
fn level(&self) -> Option<usize> {
None
}
}

pub struct Compositor {
Expand Down Expand Up @@ -137,7 +146,24 @@ impl Compositor {

// propagate events through the layers until we either find a layer that consumes it or we
// run out of layers (event bubbling)
for layer in self.layers.iter_mut().rev() {
let components_by_level: Vec<(usize, Rect)> = self
.layers
.iter()
.filter_map(|component| Some((component.level()?, component.area()?)))
.collect();
let layers = self.layers.iter_mut().rev().filter(|component| {
match (component.level(), component.area()) {
(Some(level), Some(area)) => components_by_level
.iter()
.rev()
.find(|(other_level, other_area)| {
*other_level == level && other_area.intersects(area)
})
.is_none(),
_ => false,
}
});
for layer in layers {
match layer.handle_event(event, cx) {
EventResult::Consumed(Some(callback)) => {
callbacks.push(callback);
Expand All @@ -163,7 +189,27 @@ impl Compositor {
}

pub fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
for layer in &mut self.layers {
let components_by_level: Vec<(usize, Rect)> = self
.layers
.iter()
.filter_map(|component| Some((component.level()?, component.area()?)))
.collect();
let layers = self
.layers
.iter_mut()
.rev()
.filter(|component| match (component.level(), component.area()) {
(Some(level), Some(area)) => components_by_level
.iter()
.rev()
.find(|(other_level, other_area)| {
*other_level == level && other_area.intersects(area)
})
.is_none(),
_ => false,
})
.rev();
for layer in layers {
layer.render(area, surface, cx);
}
}
Expand Down
4 changes: 4 additions & 0 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,8 @@ impl Component for Completion {
markdown_doc.render(area, surface, cx);
}
}

fn level(&self) -> Option<usize> {
Some(0)
}
}
14 changes: 13 additions & 1 deletion helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct Popup<T: Component> {
ignore_escape_key: bool,
id: &'static str,
has_scrollbar: bool,
level: Option<usize>,
area: Rect,
}

impl<T: Component> Popup<T> {
Expand All @@ -39,9 +41,15 @@ impl<T: Component> Popup<T> {
ignore_escape_key: false,
id,
has_scrollbar: true,
level: None,
area: Rect::default(),
}
}

pub fn set_level(mut self, level: usize) {
self.level = Some(level);
}

pub fn position(mut self, pos: Option<Position>) -> Self {
self.position = pos;
self
Expand Down Expand Up @@ -231,7 +239,7 @@ impl<T: Component> Component for Popup<T> {

// clip to viewport
let area = viewport.intersection(Rect::new(rel_x, rel_y, self.size.0, self.size.1));

self.area = area;
// clear area
let background = cx.editor.theme.get("ui.popup");
surface.clear_with(area, background);
Expand Down Expand Up @@ -274,6 +282,10 @@ impl<T: Component> Component for Popup<T> {
}
}

fn area(&self) -> Option<Rect> {
Some(self.area)
}

fn id(&self) -> Option<&'static str> {
Some(self.id)
}
Expand Down