diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java index a78abffa2..88e2390ba 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java @@ -1470,6 +1470,10 @@ private void skipOverFoldedParagraphs( ObservableValue ob, In { if ( getCell( newParagraph ).isFolded() ) { + // Prevent Ctrl+A and Ctrl+End breaking when the last paragraph is folded + // github.com/FXMisc/RichTextFX/pull/965#issuecomment-706268116 + if ( newParagraph == getParagraphs().size() - 1 ) return; + int skip = (newParagraph - prevParagraph > 0) ? +1 : -1; int p = newParagraph + skip; diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java index dd035955f..0c382587b 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java @@ -240,7 +240,7 @@ public Paragraph getParagraph() { public double getCaretOffsetX(T caret) { layout(); // ensure layout, is a no-op if not dirty - checkWithinParagraph(caret); + if ( isVisible() /* notFolded */ ) checkWithinParagraph(caret); Bounds bounds = caret.getLayoutBounds(); return (bounds.getMinX() + bounds.getMaxX()) / 2; }