aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorGokul Soumya2022-02-08 03:31:24 +0000
committerBlaž Hrastnik2022-02-08 07:44:39 +0000
commit5995568c1d23239a230d6e1bcbfc370e5c8cd287 (patch)
tree65e5712004af4889d95a0fafbb2d484a83b07293 /helix-term
parent547c3ecd0c72f2b88fa2b3c1321ad9adcb42ee47 (diff)
Prevent multiple code action popups
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs14
-rw-r--r--helix-term/src/compositor.rs10
2 files changed, 13 insertions, 11 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index d9fb2d55..e766417c 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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)
};
@@ -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));
},
)
}
@@ -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));
}
},
);
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index 321f56a5..dd7ebe1d 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -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()
}