From a9ce57f6c5b8815ebb28cb343977001cc9fb3942 Mon Sep 17 00:00:00 2001 From: crschnick Date: Sat, 19 Aug 2023 20:28:19 +0000 Subject: [PATCH] Fix NPE on file rename undo --- .../app/comp/base/LazyTextFieldComp.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/base/LazyTextFieldComp.java b/app/src/main/java/io/xpipe/app/comp/base/LazyTextFieldComp.java index 80c8c34d..e83cc895 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/LazyTextFieldComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/LazyTextFieldComp.java @@ -12,6 +12,8 @@ import javafx.scene.layout.StackPane; import lombok.Builder; import lombok.Value; +import java.util.Objects; + public class LazyTextFieldComp extends Comp { private final Property currentValue; @@ -53,9 +55,8 @@ public class LazyTextFieldComp extends Comp { }); // Handles external updates - PlatformThread.sync(appliedValue).addListener((observable, oldValue, newValue) -> { - r.setText(newValue); - currentValue.setValue(newValue); + PlatformThread.sync(appliedValue).addListener((observable, oldValue, n) -> { + currentValue.setValue(n); }); r.setPrefWidth(0); @@ -64,8 +65,16 @@ public class LazyTextFieldComp extends Comp { sp.prefHeightProperty().bind(r.prefHeightProperty()); r.setDisable(true); - SimpleChangeListener.apply(currentValue, val -> { - PlatformThread.runLaterIfNeeded(() -> r.setText(val)); + SimpleChangeListener.apply(currentValue, n -> { + PlatformThread.runLaterIfNeeded(() -> { + // Check if control value is the same. Then don't set it as that might cause bugs + if (Objects.equals(r.getText(), n) + || (n == null && r.getText().isEmpty())) { + return; + } + + r.setText(n); + }); }); r.textProperty().addListener((observable, oldValue, newValue) -> { currentValue.setValue(newValue);