aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/compositor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/compositor.rs')
-rw-r--r--helix-term/src/compositor.rs12
1 files changed, 12 insertions, 0 deletions
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