fix: Save toolbar button and saveChanges dialog discard an in-progress cell edit

Clicking the Save icon in the toolbar, or the Save button in the "save
changes?" dialog, called file.save directly without first committing a
cell edit still in progress (e.g. double-click a cell, type a new value,
then click Save with the mouse instead of pressing Enter). The pending
text in EditState was never flushed into the document, so the saved
file still held the pre-edit value, silently.

The File > Save menu item already guards against this
(app.commit_edit(...) before running the command); this applies the
same guard to the toolbar icon and the saveChanges dialog's Save button.
This commit is contained in:
Dejan Kocić
2026-10-11 00:35:45 +02:00
parent 90b3c41eec
commit a0dc1abce1
2 changed files with 6 additions and 2 deletions
+2 -1
View File
@@ -810,7 +810,8 @@ pub fn show(app: &mut SheetApp, ctx: &egui::Context) {
if ui.button("Cancel").clicked() {
open = false;
}
if ui.button("Save").clicked() {
// File operations must include the cell the user is still editing (as the File > Save menu item already does).
if ui.button("Save").clicked() && app.commit_edit(0, 0, false, false) {
app.run_or_alert("file.save", json!({}));
if app.session.active().is_some_and(|x| !x.is_dirty()) {
app.run_or_alert("file.close", json!({"force": true}));
+4 -1
View File
@@ -44,7 +44,10 @@ pub fn title_bar(app: &mut SheetApp, ui: &mut Ui) {
if icon_button(ui, Icon::Home, t.text_dim, "Home", vec2(26.0, 26.0)).clicked() {
app.open_dialog("start", json!({}));
}
if icon_button(ui, Icon::Save, t.text_dim, "Save (⌘S)", vec2(26.0, 26.0)).clicked() {
if icon_button(ui, Icon::Save, t.text_dim, "Save (⌘S)", vec2(26.0, 26.0)).clicked()
// File operations must include the cell the user is still editing (as the File > Save menu item already does).
&& app.commit_edit(0, 0, false, false)
{
app.run_or_alert("file.save", json!({}));
}
let can_undo = app.session.active().is_some_and(|d| !d.undo.is_empty());