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 <martyk@tuta.io>
Co-authored-by: Kirawi <67773714+kirawi@users.noreply.github.com>
This commit is contained in:
Marty 2024-06-05 18:47:15 +02:00 committed by GitHub
parent 31bcde360c
commit c39cde8fc2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -142,6 +142,17 @@ impl<'a> Context<'a> {
pub fn count(&self) -> usize { pub fn count(&self) -> usize {
self.count.map_or(1, |v| v.get()) 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] #[inline]
@ -5828,8 +5839,11 @@ 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))] #[cfg(not(windows))]
{
_cx.block_try_flush_writes().ok();
signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap();
} }
}
fn add_newline_above(cx: &mut Context) { fn add_newline_above(cx: &mut Context) {
add_newline_impl(cx, Open::Above); add_newline_impl(cx, Open::Above);