Skip to content

Commit 66737c6

Browse files
authored
Close prompts when switching windows (#13620)
1 parent fbf6407 commit 66737c6

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

helix-term/src/compositor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ impl Compositor {
136136
Some(self.layers.remove(idx))
137137
}
138138

139+
pub fn remove_type<T: 'static>(&mut self) {
140+
let type_name = std::any::type_name::<T>();
141+
self.layers
142+
.retain(|component| component.type_name() != type_name);
143+
}
139144
pub fn handle_event(&mut self, event: &Event, cx: &mut Context) -> bool {
140145
// If it is a key event, a macro is being recorded, and a macro isn't being replayed,
141146
// push the key event to the recording.

helix-term/src/handlers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod auto_save;
1616
pub mod completion;
1717
mod diagnostics;
1818
mod document_colors;
19+
mod prompt;
1920
mod signature_help;
2021
mod snippet;
2122

@@ -43,5 +44,6 @@ pub fn setup(config: Arc<ArcSwap<Config>>) -> Handlers {
4344
diagnostics::register_hooks(&handlers);
4445
snippet::register_hooks(&handlers);
4546
document_colors::register_hooks(&handlers);
47+
prompt::register_hooks(&handlers);
4648
handlers
4749
}

helix-term/src/handlers/prompt.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use helix_event::register_hook;
2+
use helix_view::events::DocumentFocusLost;
3+
use helix_view::handlers::Handlers;
4+
5+
use crate::job::{self};
6+
use crate::ui;
7+
8+
pub(super) fn register_hooks(_handlers: &Handlers) {
9+
register_hook!(move |_event: &mut DocumentFocusLost<'_>| {
10+
job::dispatch_blocking(move |_, compositor| {
11+
if compositor.find::<ui::Prompt>().is_some() {
12+
compositor.remove_type::<ui::Prompt>();
13+
}
14+
});
15+
Ok(())
16+
});
17+
}

0 commit comments

Comments
 (0)