From cc4fff5ae107ebcb19f5bdec922c4cadbfbff355 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 21 Dec 2018 15:23:20 +0100 Subject: [PATCH] avoid scrolling current line to top of view when start editing --- .../main/java/org/fxmisc/richtext/GenericStyledArea.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java index 8c6b7bc2f..070032b7a 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java @@ -1479,6 +1479,12 @@ public void dispose() { /** Assumes this method is called within a {@link #suspendVisibleParsWhile(Runnable)} block */ private void followCaret() { int parIdx = getCurrentParagraph(); + + // Make sure that cells are up-to-date to avoid scrolling current line to top when + // start editing, which may occur under certain circumstances. E.g. if having embedded + // images, which results in some lines that are much higher then the average line height. + virtualFlow.layout(); + Cell, ParagraphBox> cell = virtualFlow.getCell(parIdx); Bounds caretBounds = cell.getNode().getCaretBounds(caretSelectionBind.getUnderlyingCaret()); double graphicWidth = cell.getNode().getGraphicPrefWidth();