Skip to content

Commit fa5bc8f

Browse files
authored
Merge pull request #375 from JordanMartinez/fixPopupIssue
Relayout popup when any of its settings are invalidated
2 parents f22bbd8 + 06bf321 commit fa5bc8f

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,13 @@ public StyledTextArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyPa
605605
EventStream<?> caretDirty = merge(caretPosDirty, paragraphsDirty, selectionDirty);
606606
subscribeTo(caretDirty, x -> requestFollowCaret());
607607

608+
// relayout the popup when any of its settings values change (besides the caret being dirty)
609+
EventStream<?> popupAlignmentDirty = invalidationsOf(popupAlignmentProperty());
610+
EventStream<?> popupAnchorAdjustmentDirty = invalidationsOf(popupAnchorAdjustmentProperty());
611+
EventStream<?> popupAnchorOffsetDirty = invalidationsOf(popupAnchorOffsetProperty());
612+
EventStream<?> popupDirty = merge(popupAlignmentDirty, popupAnchorAdjustmentDirty, popupAnchorOffsetDirty);
613+
subscribeTo(popupDirty, x -> layoutPopup());
614+
608615
// whether or not to display the caret
609616
EventStream<Boolean> blinkCaret = EventStreams.valuesOf(showCaretProperty())
610617
.flatMap(mode -> {
@@ -1098,12 +1105,7 @@ protected void layoutChildren() {
10981105
}
10991106

11001107
// position popup
1101-
PopupWindow popup = getPopupWindow();
1102-
PopupAlignment alignment = getPopupAlignment();
1103-
UnaryOperator<Point2D> adjustment = _popupAnchorAdjustment.getValue();
1104-
if(popup != null) {
1105-
positionPopup(popup, alignment, adjustment);
1106-
}
1108+
layoutPopup();
11071109
}
11081110

11091111
/* ********************************************************************** *
@@ -1202,6 +1204,15 @@ private int getParagraphOffset(int parIdx) {
12021204
return position(parIdx, 0).toOffset();
12031205
}
12041206

1207+
private void layoutPopup() {
1208+
PopupWindow popup = getPopupWindow();
1209+
PopupAlignment alignment = getPopupAlignment();
1210+
UnaryOperator<Point2D> adjustment = _popupAnchorAdjustment.getValue();
1211+
if(popup != null) {
1212+
positionPopup(popup, alignment, adjustment);
1213+
}
1214+
}
1215+
12051216
private void positionPopup(
12061217
PopupWindow popup,
12071218
PopupAlignment alignment,

0 commit comments

Comments
 (0)