Unnamed repository; edit this file 'description' to name the repository.
Close prompts when switching windows (#13620)
CalebLarsen 5 months ago
parent fbf6407 · commit 66737c6
-rw-r--r--helix-term/src/compositor.rs5
-rw-r--r--helix-term/src/handlers.rs2
-rw-r--r--helix-term/src/handlers/prompt.rs17
3 files changed, 24 insertions, 0 deletions
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index 28c8651a..266a8aec 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<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.
diff --git a/helix-term/src/handlers.rs b/helix-term/src/handlers.rs
index 9c46a650..25cab6a3 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<ArcSwap<Config>>) -> 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 00000000..2270f58b
--- /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::<ui::Prompt>().is_some() {
+ compositor.remove_type::<ui::Prompt>();
+ }
+ });
+ Ok(())
+ });
+}