Skip to content

Commit

Permalink
Prevent multiple code action popups
Browse files Browse the repository at this point in the history
  • Loading branch information
sudormrfbin authored and archseer committed Feb 8, 2022
1 parent 547c3ec commit 5995568
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 3 additions & 11 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2792,11 +2792,7 @@ pub mod cmd {
Box::new(move |editor: &mut Editor, compositor: &mut Compositor| {
let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
let popup = Popup::new("hover", contents);
if let Some(doc_popup) = compositor.find_id("hover") {
*doc_popup = popup;
} else {
compositor.push(Box::new(popup));
}
compositor.replace_or_push("hover", Box::new(popup));
});
Ok(call)
};
Expand Down Expand Up @@ -3537,7 +3533,7 @@ pub fn code_action(cx: &mut Context) {
vertical: 1,
horizontal: 1,
});
compositor.push(Box::new(popup))
compositor.replace_or_push("code-action", Box::new(popup));
},
)
}
Expand Down Expand Up @@ -5465,11 +5461,7 @@ fn hover(cx: &mut Context) {
let contents =
ui::Markdown::new(contents, editor.syn_loader.clone()).style_group("hover");
let popup = Popup::new("hover", contents);
if let Some(doc_popup) = compositor.find_id("hover") {
*doc_popup = popup;
} else {
compositor.push(Box::new(popup));
}
compositor.replace_or_push("hover", Box::new(popup));
}
},
);
Expand Down
10 changes: 10 additions & 0 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ impl Compositor {
self.layers.push(layer);
}

/// Replace a component that has the given `id` with the new layer and if
/// no component is found, push the layer normally.
pub fn replace_or_push(&mut self, id: &'static str, layer: Box<dyn Component>) {
if let Some(component) = self.find_id(id) {
*component = layer;
} else {
self.push(layer)
}
}

pub fn pop(&mut self) -> Option<Box<dyn Component>> {
self.layers.pop()
}
Expand Down

0 comments on commit 5995568

Please sign in to comment.