mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-28 20:56:54 -06:00
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:
@@ -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}));
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user