mirror of https://github.com/helix-editor/helix
Only use a single documentation popup (#1241)
parent
d08bdfa838
commit
29c053e84e
|
@ -5130,8 +5130,12 @@ fn hover(cx: &mut Context) {
|
||||||
// skip if contents empty
|
// skip if contents empty
|
||||||
|
|
||||||
let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
|
let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
|
||||||
let popup = Popup::new(contents);
|
let popup = Popup::new("documentation", contents);
|
||||||
compositor.push(Box::new(popup));
|
if let Some(doc_popup) = compositor.find_id("documentation") {
|
||||||
|
*doc_popup = popup;
|
||||||
|
} else {
|
||||||
|
compositor.push(Box::new(popup));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -64,6 +64,10 @@ pub trait Component: Any + AnyComponent {
|
||||||
fn type_name(&self) -> &'static str {
|
fn type_name(&self) -> &'static str {
|
||||||
std::any::type_name::<Self>()
|
std::any::type_name::<Self>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn id(&self) -> Option<&'static str> {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
@ -184,6 +188,14 @@ impl Compositor {
|
||||||
.find(|component| component.type_name() == type_name)
|
.find(|component| component.type_name() == type_name)
|
||||||
.and_then(|component| component.as_any_mut().downcast_mut())
|
.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
|
// View casting, taken straight from Cursive
|
||||||
|
|
|
@ -168,7 +168,7 @@ impl Completion {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
let popup = Popup::new(menu);
|
let popup = Popup::new("completion", menu);
|
||||||
let mut completion = Self {
|
let mut completion = Self {
|
||||||
popup,
|
popup,
|
||||||
start_offset,
|
start_offset,
|
||||||
|
|
|
@ -16,15 +16,17 @@ pub struct Popup<T: Component> {
|
||||||
position: Option<Position>,
|
position: Option<Position>,
|
||||||
size: (u16, u16),
|
size: (u16, u16),
|
||||||
scroll: usize,
|
scroll: usize,
|
||||||
|
id: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Component> Popup<T> {
|
impl<T: Component> Popup<T> {
|
||||||
pub fn new(contents: T) -> Self {
|
pub fn new(id: &'static str, contents: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
contents,
|
contents,
|
||||||
position: None,
|
position: None,
|
||||||
size: (0, 0),
|
size: (0, 0),
|
||||||
scroll: 0,
|
scroll: 0,
|
||||||
|
id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,4 +145,8 @@ impl<T: Component> Component for Popup<T> {
|
||||||
|
|
||||||
self.contents.render(area, surface, cx);
|
self.contents.render(area, surface, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn id(&self) -> Option<&'static str> {
|
||||||
|
Some(self.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue