Commit both corner-resize dimensions in one host transaction
This commit is contained in:
@@ -109,7 +109,8 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
private DocumentSnapshot draft;
|
||||
private FxmlProjection projection;
|
||||
private DesignerWorkflow workflow;
|
||||
private boolean loading, closed, pending, last;
|
||||
private boolean loading, closed, pending, last, canvasCommitQueued;
|
||||
private long canvasGeneration;
|
||||
private final java.util.concurrent.atomic.AtomicLong renderSequence =
|
||||
new java.util.concurrent.atomic.AtomicLong();
|
||||
private AutoCloseable changes;
|
||||
@@ -205,6 +206,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
.addListener(
|
||||
(o, a, b) -> {
|
||||
if (!loading) {
|
||||
flushCanvas();
|
||||
if (pending && submittedSource == null) submittedSource = pendingBase;
|
||||
commitSource();
|
||||
workflow.cancel();
|
||||
@@ -338,6 +340,8 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
private void load(DocumentSnapshot value) {
|
||||
if (closed) return;
|
||||
loading = true;
|
||||
canvasCommitQueued = false;
|
||||
canvasGeneration++;
|
||||
renderSequence.incrementAndGet();
|
||||
workflow.cancel();
|
||||
try {
|
||||
@@ -441,6 +445,28 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void canvasChanged() {
|
||||
if (loading || pending || closed || canvasCommitQueued) return;
|
||||
// Kit's corner-resize gesture pushes one job per dimension on the same FX event turn.
|
||||
// Capture the completed gesture, not the intermediate width-only document.
|
||||
canvasCommitQueued = true;
|
||||
long generation = ++canvasGeneration;
|
||||
var projectedDocument = kit.editor().getFxomDocument();
|
||||
var expectedDraft = draft;
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
if (generation != canvasGeneration || closed) return;
|
||||
if (projectedDocument != kit.editor().getFxomDocument() || draft != expectedDraft) {
|
||||
canvasCommitQueued = false;
|
||||
return;
|
||||
}
|
||||
flushCanvas();
|
||||
});
|
||||
}
|
||||
|
||||
private void flushCanvas() {
|
||||
if (!canvasCommitQueued) return;
|
||||
canvasCommitQueued = false;
|
||||
canvasGeneration++;
|
||||
if (loading || pending || closed) return;
|
||||
try {
|
||||
submit(
|
||||
@@ -454,6 +480,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
|
||||
private void withDraft(Runnable action) {
|
||||
if (document == null) return;
|
||||
flushCanvas();
|
||||
if (pending || !source.getText().equals(draft.text())) {
|
||||
commitSource();
|
||||
status.setText("Finishing source edit; repeat the action when synchronized");
|
||||
@@ -689,6 +716,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void flushInto(CompletableFuture<Void> result, long deadline) {
|
||||
flushCanvas();
|
||||
if (System.nanoTime() > deadline) {
|
||||
result.completeExceptionally(
|
||||
new IllegalStateException("Source edit could not be synchronized"));
|
||||
|
||||
Reference in New Issue
Block a user