diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 28c8651a2..266a8aec8 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -136,6 +136,11 @@ impl Compositor { Some(self.layers.remove(idx)) } + pub fn remove_type(&mut self) { + let type_name = std::any::type_name::(); + self.layers + .retain(|component| component.type_name() != type_name); + } pub fn handle_event(&mut self, event: &Event, cx: &mut Context) -> bool { // If it is a key event, a macro is being recorded, and a macro isn't being replayed, // push the key event to the recording. diff --git a/helix-term/src/handlers.rs b/helix-term/src/handlers.rs index 9c46a6503..25cab6a36 100644 --- a/helix-term/src/handlers.rs +++ b/helix-term/src/handlers.rs @@ -16,6 +16,7 @@ mod auto_save; pub mod completion; mod diagnostics; mod document_colors; +mod prompt; mod signature_help; mod snippet; @@ -43,5 +44,6 @@ pub fn setup(config: Arc>) -> Handlers { diagnostics::register_hooks(&handlers); snippet::register_hooks(&handlers); document_colors::register_hooks(&handlers); + prompt::register_hooks(&handlers); handlers } diff --git a/helix-term/src/handlers/prompt.rs b/helix-term/src/handlers/prompt.rs new file mode 100644 index 000000000..2270f58b5 --- /dev/null +++ b/helix-term/src/handlers/prompt.rs @@ -0,0 +1,17 @@ +use helix_event::register_hook; +use helix_view::events::DocumentFocusLost; +use helix_view::handlers::Handlers; + +use crate::job::{self}; +use crate::ui; + +pub(super) fn register_hooks(_handlers: &Handlers) { + register_hook!(move |_event: &mut DocumentFocusLost<'_>| { + job::dispatch_blocking(move |_, compositor| { + if compositor.find::().is_some() { + compositor.remove_type::(); + } + }); + Ok(()) + }); +}