Keep form edits anchored across native autosaves

This commit is contained in:
2026-11-24 15:24:07 +01:00
parent 93a9f04b11
commit 43267824d7
5 changed files with 118 additions and 12 deletions
@@ -446,18 +446,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
bindings.setExpanded(false);
formEditor =
new FormEditor(
edit ->
flush()
.whenComplete(
(ok, error) ->
fx(
() -> {
if (error != null) report(error);
else if (draft.writable() && draft.text().equals(edit.source()))
submit(edit.changes(), "Edit form");
else
status.setText("Document changed; select the control again.");
})),
this::editForm,
index -> {
if (loading || projection == null || kit.editor().getFxomDocument() == null) return;
String id = projection.canvasId(index);
@@ -763,6 +752,36 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
: null;
}
private void editForm(FormDocument.Edit edit) {
flush()
.whenComplete(
(ok, error) ->
fx(
() -> {
if (error != null) {
report(error);
return;
}
if (pending) {
status.setText("Finishing the previous edit; repeat the form action.");
return;
}
pending = true;
pendingBase = edit.source();
pendingVisual = edit.changes();
document
.snapshot()
.thenCompose(
latest ->
document.apply(
new EditBatch(
latest.revision(),
"Edit form",
FormDocument.forCurrentText(edit, latest.text()))))
.whenComplete(this::updated);
}));
}
private void replace(String text, String name) {
if (draft == null || pending) return;
submit(difference(draft.text(), text), name);