aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorKirawi2021-12-08 07:11:18 +0000
committerGitHub2021-12-08 07:11:18 +0000
commit29c053e84e2624feb786f520ebae4c752bc23279 (patch)
treed537982f3f7304142a84b0affacc5f830bca105c /helix-term
parentd08bdfa838098769afc59146b62f9d613d4a7ff4 (diff)
Only use a single documentation popup (#1241)
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs8
-rw-r--r--helix-term/src/compositor.rs12
-rw-r--r--helix-term/src/ui/completion.rs2
-rw-r--r--helix-term/src/ui/popup.rs8
4 files changed, 26 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 4910790a..1f7a2275 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -5130,8 +5130,12 @@ fn hover(cx: &mut Context) {
// skip if contents empty
let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
- let popup = Popup::new(contents);
- compositor.push(Box::new(popup));
+ let popup = Popup::new("documentation", contents);
+ if let Some(doc_popup) = compositor.find_id("documentation") {
+ *doc_popup = popup;
+ } else {
+ compositor.push(Box::new(popup));
+ }
}
},
);
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index 3a644750..37e67973 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -64,6 +64,10 @@ pub trait Component: Any + AnyComponent {
fn type_name(&self) -> &'static str {
std::any::type_name::<Self>()
}
+
+ fn id(&self) -> Option<&'static str> {
+ None
+ }
}
use anyhow::Error;
@@ -184,6 +188,14 @@ impl Compositor {
.find(|component| component.type_name() == type_name)
.and_then(|component| component.as_any_mut().downcast_mut())
}
+
+ pub fn find_id<T: 'static>(&mut self, id: &'static str) -> Option<&mut T> {
+ let type_name = std::any::type_name::<T>();
+ self.layers
+ .iter_mut()
+ .find(|component| component.type_name() == type_name && component.id() == Some(id))
+ .and_then(|component| component.as_any_mut().downcast_mut())
+ }
}
// View casting, taken straight from Cursive
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index dd782d29..fcd63199 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -168,7 +168,7 @@ impl Completion {
}
};
});
- let popup = Popup::new(menu);
+ let popup = Popup::new("completion", menu);
let mut completion = Self {
popup,
start_offset,
diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs
index 8f7921a1..a5310b23 100644
--- a/helix-term/src/ui/popup.rs
+++ b/helix-term/src/ui/popup.rs
@@ -16,15 +16,17 @@ pub struct Popup<T: Component> {
position: Option<Position>,
size: (u16, u16),
scroll: usize,
+ id: &'static str,
}
impl<T: Component> Popup<T> {
- pub fn new(contents: T) -> Self {
+ pub fn new(id: &'static str, contents: T) -> Self {
Self {
contents,
position: None,
size: (0, 0),
scroll: 0,
+ id,
}
}
@@ -143,4 +145,8 @@ impl<T: Component> Component for Popup<T> {
self.contents.render(area, surface, cx);
}
+
+ fn id(&self) -> Option<&'static str> {
+ Some(self.id)
+ }
}