Close prompts when switching windows (#13620)

This commit is contained in:
CalebLarsen
2025-09-15 08:32:43 -05:00
committed by GitHub
parent fbf6407ab3
commit 66737c6a4f
3 changed files with 24 additions and 0 deletions

View File

@@ -136,6 +136,11 @@ impl Compositor {
Some(self.layers.remove(idx))
}
pub fn remove_type<T: 'static>(&mut self) {
let type_name = std::any::type_name::<T>();
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.

View File

@@ -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<ArcSwap<Config>>) -> Handlers {
diagnostics::register_hooks(&handlers);
snippet::register_hooks(&handlers);
document_colors::register_hooks(&handlers);
prompt::register_hooks(&handlers);
handlers
}

View File

@@ -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::<ui::Prompt>().is_some() {
compositor.remove_type::<ui::Prompt>();
}
});
Ok(())
});
}