From d9e2bdc97a06f0bc87ce929d3dfa44c1af936e90 Mon Sep 17 00:00:00 2001 From: PotatoesFall Date: Mon, 20 May 2024 14:48:53 +0200 Subject: [PATCH 1/3] flush saves before suspending --- helix-term/src/commands.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7be2ea0954c9..fad2560fb6dd 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -142,6 +142,18 @@ 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) { + compositor::Context { + editor: self.editor, + jobs: self.jobs, + scroll: None, + } + .block_try_flush_writes() + .ok(); + } } #[inline] @@ -5826,8 +5838,9 @@ fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBeha ); } -fn suspend(_cx: &mut Context) { +fn suspend(cx: &mut Context) { #[cfg(not(windows))] + cx.block_try_flush_writes(); signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); } From 1e3c2ff4e07a46c17d768a5616abe469beffd524 Mon Sep 17 00:00:00 2001 From: Marty <58218546+PotatoesFall@users.noreply.github.com> Date: Mon, 20 May 2024 13:59:50 -0500 Subject: [PATCH 2/3] review suggestion Co-authored-by: Kirawi <67773714+kirawi@users.noreply.github.com> --- helix-term/src/commands.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index fad2560fb6dd..72817cb327e1 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5840,8 +5840,10 @@ fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBeha fn suspend(cx: &mut Context) { #[cfg(not(windows))] - cx.block_try_flush_writes(); - signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); + { + cx.block_try_flush_writes(); + signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); + } } fn add_newline_above(cx: &mut Context) { From 77831bbbcf3f27b3481c401137e4353cce0412b2 Mon Sep 17 00:00:00 2001 From: PotatoesFall Date: Tue, 4 Jun 2024 23:43:33 +0200 Subject: [PATCH 3/3] review changes --- helix-term/src/commands.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 72817cb327e1..9adda602d528 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -145,14 +145,13 @@ impl<'a> Context<'a> { /// 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) { + pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> { compositor::Context { editor: self.editor, jobs: self.jobs, scroll: None, } .block_try_flush_writes() - .ok(); } } @@ -5838,10 +5837,10 @@ fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBeha ); } -fn suspend(cx: &mut Context) { +fn suspend(_cx: &mut Context) { #[cfg(not(windows))] { - cx.block_try_flush_writes(); + _cx.block_try_flush_writes().ok(); signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); } }