modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TextFieldSkin.java
Print this page
rev 7112 : RT-36660: [TextField] Arrow scrolling movement unexpected when text overflows
*** 469,504 ****
@Override public double computeBaselineOffset(double topInset, double rightInset, double bottomInset, double leftInset) {
return topInset + textNode.getBaselineOffset();
}
private void updateTextPos() {
switch (getHAlignment()) {
case CENTER:
double midPoint = textRight.get() / 2;
if (usePromptText.get()) {
! promptNode.setLayoutX(midPoint - promptNode.getLayoutBounds().getWidth() / 2);
! textTranslateX.set(promptNode.getLayoutX());
} else {
! textTranslateX.set(midPoint - textNode.getLayoutBounds().getWidth() / 2);
}
break;
case RIGHT:
! textTranslateX.set(textRight.get() - textNode.getLayoutBounds().getWidth() -
! caretWidth / 2);
if (usePromptText.get()) {
promptNode.setLayoutX(textRight.get() - promptNode.getLayoutBounds().getWidth() -
caretWidth / 2);
}
break;
case LEFT:
default:
! textTranslateX.set(caretWidth / 2);
if (usePromptText.get()) {
! promptNode.layoutXProperty().set(caretWidth / 2);
}
}
}
// should be called when the padding changes, or the text box width, or
--- 469,528 ----
@Override public double computeBaselineOffset(double topInset, double rightInset, double bottomInset, double leftInset) {
return topInset + textNode.getBaselineOffset();
}
+ /**
+ * Updates the textTranslateX value for the Text node position. This is
+ * done for general layout, but care is taken to avoid resetting the
+ * position when there's a need to scroll the text due to caret movement,
+ * or when editing text that overflows on either side.
+ */
private void updateTextPos() {
+ double oldX = textTranslateX.get();
+ double newX;
+ double textNodeWidth = textNode.getLayoutBounds().getWidth();
+
switch (getHAlignment()) {
case CENTER:
double midPoint = textRight.get() / 2;
if (usePromptText.get()) {
! // If a prompt is shown (which implies that the text is
! // empty), then we align the Text node so that the caret will
! // appear at the left of the centered prompt.
! newX = midPoint - promptNode.getLayoutBounds().getWidth() / 2;
! promptNode.setLayoutX(newX);
} else {
! newX = midPoint - textNodeWidth / 2;
! }
! // Update if there is space on the right
! if (newX + textNodeWidth <= textRight.get()) {
! textTranslateX.set(newX);
}
break;
case RIGHT:
! newX = textRight.get() - textNodeWidth - caretWidth / 2;
! // Update if there is space on the right
! if (newX > oldX || newX > 0) {
! textTranslateX.set(newX);
! }
if (usePromptText.get()) {
promptNode.setLayoutX(textRight.get() - promptNode.getLayoutBounds().getWidth() -
caretWidth / 2);
}
break;
case LEFT:
default:
! newX = caretWidth / 2;
! // Update if there is space on either side.
! if (newX < oldX || newX + textNodeWidth <= textRight.get()) {
! textTranslateX.set(newX);
! }
if (usePromptText.get()) {
! promptNode.layoutXProperty().set(newX);
}
}
}
// should be called when the padding changes, or the text box width, or
*** 577,590 ****
final Bounds textBounds = textNode.localToParent(textLayoutBounds);
final Bounds clipBounds = clip.getBoundsInParent();
final Bounds caretBounds = caretPath.getLayoutBounds();
switch (getHAlignment()) {
- case CENTER:
- updateTextPos();
- break;
-
case RIGHT:
if (textBounds.getMaxX() > clipBounds.getMaxX()) {
double delta = caretMaxXOld - caretBounds.getMaxX() - textTranslateX.get();
if (textBounds.getMaxX() + delta < clipBounds.getMaxX()) {
if (textMaxXOld <= clipBounds.getMaxX()) {
--- 601,610 ----
*** 598,607 ****
--- 618,628 ----
updateTextPos();
}
break;
case LEFT:
+ case CENTER:
default:
if (textBounds.getMinX() < clipBounds.getMinX() + caretWidth / 2 &&
textBounds.getMaxX() <= clipBounds.getMaxX()) {
double delta = caretMaxXOld - caretBounds.getMaxX() - textTranslateX.get();
if (textBounds.getMaxX() + delta < clipBounds.getMaxX()) {