From 24f58d9216abf008e788f1581fbe8332d0868d60 Mon Sep 17 00:00:00 2001 From: candygoogy <186837547+candygoogy@users.noreply.github.com> Date: Thu, 8 Oct 2026 23:13:27 +0200 Subject: [PATCH] Hide the unsaved changes dialog while saving When you close a document (Ctrl+W) or exit (Ctrl+Q) and choose Save in the unsaved changes dialog, the dialog stayed open while the file was being saved. It stayed behind the Save As picker, the error dialog was drawn on top of it if saving failed, and it came back after the error or the picker was dismissed. Don't draw it while the Save As picker is open, and cancel the close or exit if saving fails or the picker is cancelled, the same as the dialog's Cancel button. --- crates/edit/src/bin/edit/draw_editor.rs | 3 +++ crates/edit/src/bin/edit/draw_filepicker.rs | 4 ++++ crates/edit/src/bin/edit/main.rs | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/edit/src/bin/edit/draw_editor.rs b/crates/edit/src/bin/edit/draw_editor.rs index 3e4ce72c979..08ee0a3eb38 100644 --- a/crates/edit/src/bin/edit/draw_editor.rs +++ b/crates/edit/src/bin/edit/draw_editor.rs @@ -195,6 +195,9 @@ pub fn draw_handle_save(ctx: &mut Context, state: &mut State) { if doc.path.is_some() { if let Err(err) = doc.save(None) { error_log_add(ctx, state, err); + // Don't keep trying to close the document (or exit) if it couldn't be saved. + state.wants_exit = false; + state.wants_close = false; } } else { // No path? Show the file picker. diff --git a/crates/edit/src/bin/edit/draw_filepicker.rs b/crates/edit/src/bin/edit/draw_filepicker.rs index 4576a7efaae..18d35e3d3ad 100644 --- a/crates/edit/src/bin/edit/draw_filepicker.rs +++ b/crates/edit/src/bin/edit/draw_filepicker.rs @@ -190,6 +190,10 @@ pub fn draw_file_picker(ctx: &mut Context, state: &mut State) { } } if ctx.modal_end() { + // Cancelling the picker also cancels closing the document (or exiting) if we're + // here because the unsaved changes dialog asked to save it first. + state.wants_exit = false; + state.wants_close = false; done = true; } diff --git a/crates/edit/src/bin/edit/main.rs b/crates/edit/src/bin/edit/main.rs index c1128c5b571..c8e53b7320e 100644 --- a/crates/edit/src/bin/edit/main.rs +++ b/crates/edit/src/bin/edit/main.rs @@ -345,7 +345,8 @@ fn draw(tui: &mut Tui, input: Option, state: &mut State) { draw_editor(ctx, state); draw_statusbar(ctx, state); - if state.wants_close { + // While the document is being saved via the file picker, hide the unsaved changes dialog. + if state.wants_close && state.wants_file_picker == StateFilePicker::None { draw_handle_wants_close(ctx, state); } if state.wants_exit {