From c39cde8fc2a99871ff1ec9118d65ae404af9e702 Mon Sep 17 00:00:00 2001 From: Marty <58218546+PotatoesFall@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:47:15 +0200 Subject: [PATCH] Flush pending writes before suspend (#10797) * flush saves before suspending * review suggestion Co-authored-by: Kirawi <67773714+kirawi@users.noreply.github.com> * review changes --------- Co-authored-by: PotatoesFall Co-authored-by: Kirawi <67773714+kirawi@users.noreply.github.com> --- helix-term/src/commands.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 021b927c..9b614067 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -142,6 +142,17 @@ impl<'a> Context<'a> { pub fn count(&self) -> usize { self.count.map_or(1, |v| v.get()) } + + /// Waits on all pending jobs, and then tries to flush all pending write + /// operations for all documents. + pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> { + compositor::Context { + editor: self.editor, + jobs: self.jobs, + scroll: None, + } + .block_try_flush_writes() + } } #[inline] @@ -5828,7 +5839,10 @@ fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBeha fn suspend(_cx: &mut Context) { #[cfg(not(windows))] - signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); + { + _cx.block_try_flush_writes().ok(); + signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); + } } fn add_newline_above(cx: &mut Context) {