From 7e29ee6daeb86fbd20a8b5eaae30b2e0f868147d Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Thu, 20 Oct 2022 21:35:02 -0400 Subject: Autosave all when the terminal loses focus (#3178) * Autosave all when the terminal loses focus * Correct comment on focus config Co-authored-by: Blaž Hrastnik * Need a block_try_flush_writes in all quit_all paths Co-authored-by: Blaž Hrastnik --- helix-term/src/ui/editor.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 73dfd52c..43b1e7a0 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1426,7 +1426,15 @@ impl Component for EditorView { Event::Mouse(event) => self.handle_mouse_event(event, &mut cx), Event::IdleTimeout => self.handle_idle_timeout(&mut cx), - Event::FocusGained | Event::FocusLost => EventResult::Ignored(None), + Event::FocusGained => EventResult::Ignored(None), + Event::FocusLost => { + if context.editor.config().auto_save { + if let Err(e) = commands::typed::write_all_impl(context, false, false) { + context.editor.set_error(format!("{}", e)); + } + } + EventResult::Consumed(None) + } } } -- cgit v1.2.3-70-g09d2