Ensure that the final properties never see a NaN
fixes #44
Change-Id: I321fede25f3f288937cfbce64050909eacb8cef3
diff --git a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/internal/ContentView.java b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/internal/ContentView.java
index 9acd9f3..7d8c85b 100644
--- a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/internal/ContentView.java
+++ b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/internal/ContentView.java
@@ -754,8 +754,29 @@
bar.setMin(0);
DoubleBinding max = this.contentBody.widthProperty().subtract(widthProperty());
DoubleBinding factor = this.contentBody.widthProperty().divide(max);
- bar.maxProperty().bind(this.contentBody.widthProperty().divide(factor));
- bar.visibleAmountProperty().bind(widthProperty().divide(factor));
+
+// DoubleProperty santizedFactor = new SimpleDoubleProperty();
+// santizedFactor.set( Double.isNaN(factor.get()) ? 1.0 : factor.get() );
+// factor.addListener( (ob,ol,ne) -> {
+// santizedFactor.set( Double.isNaN(ne.doubleValue()) ? 1.0 : ne.doubleValue() );
+// } );
+
+ maxValue = this.contentBody.widthProperty().divide(factor);
+ visibleAmount = widthProperty().divide(factor);
+
+ updateValue(maxValue.get(), bar.maxProperty());
+ updateValue(visibleAmount.get(), bar.visibleAmountProperty());
+
+ maxValue.addListener( o -> {
+ updateValue(maxValue.get(), bar.maxProperty());
+ });
+ visibleAmount.addListener( o -> {
+ updateValue(visibleAmount.get(), bar.visibleAmountProperty());
+ });
+
+// bar.maxProperty().bind(maxValue);
+// bar.visibleAmountProperty().bind(visibleAmount);
+
this.offsetX.bind(bar.valueProperty());
this.widthProperty().addListener((x, o, n) -> {
@@ -765,6 +786,14 @@
});
}
+ private void updateValue(double v, DoubleProperty p) {
+ if( Double.isNaN(v) ) {
+ p.set(0);
+ } else {
+ p.set(v);
+ }
+ }
+
public void bindVerticalScrollbar(ScrollBar bar) {
this.heightProperty().addListener((x, o, n) -> {
if (!Double.isNaN(bar.getMax()) && !Double.isNaN(bar.getValue())) {
@@ -788,6 +817,10 @@
private int insertionMarkerIndex = -1;
+ private DoubleBinding maxValue;
+
+ private DoubleBinding visibleAmount;
+
public void updateInsertionMarkerIndex(int index) {
if (this.insertionMarkerIndex != index) {
this.insertionMarkerIndex = index;