From 06bf3210fd4ec31b6026dff97c719042c74da530 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 4 Oct 2016 12:05:31 -0700 Subject: [PATCH] Relayout popup when any of its settings are invalidated --- .../org/fxmisc/richtext/StyledTextArea.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java b/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java index 70006c8db..913f1f869 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java @@ -605,6 +605,13 @@ public StyledTextArea(PS initialParagraphStyle, BiConsumer applyPa EventStream caretDirty = merge(caretPosDirty, paragraphsDirty, selectionDirty); subscribeTo(caretDirty, x -> requestFollowCaret()); + // relayout the popup when any of its settings values change (besides the caret being dirty) + EventStream popupAlignmentDirty = invalidationsOf(popupAlignmentProperty()); + EventStream popupAnchorAdjustmentDirty = invalidationsOf(popupAnchorAdjustmentProperty()); + EventStream popupAnchorOffsetDirty = invalidationsOf(popupAnchorOffsetProperty()); + EventStream popupDirty = merge(popupAlignmentDirty, popupAnchorAdjustmentDirty, popupAnchorOffsetDirty); + subscribeTo(popupDirty, x -> layoutPopup()); + // whether or not to display the caret EventStream blinkCaret = EventStreams.valuesOf(showCaretProperty()) .flatMap(mode -> { @@ -1098,12 +1105,7 @@ protected void layoutChildren() { } // position popup - PopupWindow popup = getPopupWindow(); - PopupAlignment alignment = getPopupAlignment(); - UnaryOperator adjustment = _popupAnchorAdjustment.getValue(); - if(popup != null) { - positionPopup(popup, alignment, adjustment); - } + layoutPopup(); } /* ********************************************************************** * @@ -1202,6 +1204,15 @@ private int getParagraphOffset(int parIdx) { return position(parIdx, 0).toOffset(); } + private void layoutPopup() { + PopupWindow popup = getPopupWindow(); + PopupAlignment alignment = getPopupAlignment(); + UnaryOperator adjustment = _popupAnchorAdjustment.getValue(); + if(popup != null) { + positionPopup(popup, alignment, adjustment); + } + } + private void positionPopup( PopupWindow popup, PopupAlignment alignment,