diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java index 8a3b48c0f..c7cf5585f 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java @@ -1187,7 +1187,8 @@ public void setLineHighlighterOn( boolean show ) { int p = getCurrentParagraph(); int start = getCurrentLineStartInParargraph(); - int end = getCurrentLineEndInParargraph() + 1; // +1 for empty lines + int end = getCurrentLineEndInParargraph(); + if (end == 0) end++;// +1 for empty lines lineHighlighter.selectRange( p, start, p, end ); } }; diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java index 02a7553cb..562e50d2e 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java @@ -95,9 +95,6 @@ public final ObservableMap, SelectionPath> selectionsPrope this.text = new ParagraphText<>(par, nodeFactory); applyParagraphStyle.accept(this.text, par.getParagraphStyle()); - // Apply line-spacing (in a paragraph) to between paragraphs as well. Can be overriden with -fx-padding CSS. - text.lineSpacingProperty().addListener( (ob,ov,nv) -> setPadding( new Insets( 0, 0, nv.doubleValue(), 0 ) ) ); - // start at -1 so that the first time it is displayed, the caret at pos 0 is not // accidentally removed from its parent and moved to this node's ParagraphText // before this node gets updated to its real index and therefore removes @@ -240,21 +237,20 @@ protected double computePrefWidth(double ignoredHeight) { protected double computePrefHeight(double width) { Insets insets = getInsets(); double overhead = getGraphicPrefWidth() + insets.getLeft() + insets.getRight(); - return text.prefHeight(width - overhead) + insets.getTop() + insets.getBottom(); + return text.prefHeight(width - overhead) + insets.getTop() + insets.getBottom() + text.getLineSpacing(); } @Override - protected - void layoutChildren() { + protected void layoutChildren() { Insets ins = getInsets(); double w = getWidth() - ins.getLeft() - ins.getRight(); double h = getHeight() - ins.getTop() - ins.getBottom(); double graphicWidth = getGraphicPrefWidth(); + double half = text.getLineSpacing() / 2.0; - text.resizeRelocate(graphicWidth + ins.getLeft(), ins.getTop(), w - graphicWidth, h); + text.resizeRelocate(graphicWidth + ins.getLeft(), ins.getTop() + half, w - graphicWidth, h - half); - graphic.ifPresent(g -> g.resizeRelocate(graphicOffset.get() + ins.getLeft(), ins.getTop(), graphicWidth, h + ins.getBottom())); - // h + ins.getBottom() so that there aren't gaps when -fx-line-spacing or -fx-padding is active. + graphic.ifPresent(g -> g.resizeRelocate(graphicOffset.get() + ins.getLeft(), ins.getTop(), graphicWidth, h)); } double getGraphicPrefWidth() { diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java index b4a23192c..755b5e364 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java @@ -361,7 +361,7 @@ private PathElement[] getRangeShapeSafely(int start, int end) { } else { shape = getRangeShape(start, paragraph.length()); // Since this might be a wrapped multi-line paragraph, - // there may be multiple groups of (1 MoveTo, 3 LineTo objects) for each line: + // there may be multiple groups of (1 MoveTo, 4 LineTo objects) for each line: // MoveTo(topLeft), LineTo(topRight), LineTo(bottomRight), LineTo(bottomLeft) // We only need to adjust the top right and bottom right corners to extend to the @@ -378,6 +378,22 @@ private PathElement[] getRangeShapeSafely(int start, int end) { } } + if ( getLineSpacing() > 0 ) { + double half = getLineSpacing() / 2.0; + for ( int g = 0; g < shape.length; g += 5 ) { + MoveTo tl = (MoveTo) shape[g]; + tl.setY( tl.getY()-half ); + LineTo tr = (LineTo) shape[g+1]; + tr.setY( tl.getY() ); + LineTo br = (LineTo) shape[g+2]; + br.setY( br.getY()+half ); + LineTo bl = (LineTo) shape[g+3]; + bl.setY( br.getY() ); + LineTo t2 = (LineTo) shape[g+4]; + t2.setY( tl.getY() ); + } + } + if (getLineCount() > 1) { // adjust right corners of wrapped lines boolean wrappedAtEndPos = (end > 0 && getLineOfCharacter(end) > getLineOfCharacter(end - 1));