Skip to content

Commit e2c58c6

Browse files
authored
Merge pull request #857 from Jugen/line_highlighter_width_fix
Fixed line highlighter not adjusting to area's width changes
2 parents ce17521 + 0318809 commit e2c58c6

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.function.IntSupplier;
1717
import java.util.function.IntUnaryOperator;
1818

19+
import javafx.application.Platform;
1920
import javafx.beans.NamedArg;
2021
import javafx.beans.property.BooleanProperty;
2122
import javafx.beans.property.DoubleProperty;
@@ -52,6 +53,7 @@
5253
import javafx.scene.shape.PathElement;
5354
import javafx.scene.text.TextFlow;
5455

56+
import javafx.application.Platform;
5557
import org.fxmisc.flowless.Cell;
5658
import org.fxmisc.flowless.VirtualFlow;
5759
import org.fxmisc.flowless.VirtualFlowHit;
@@ -1168,18 +1170,26 @@ public void setLineHighlighterOn( boolean show )
11681170
} );
11691171
} );
11701172

1171-
Consumer<Bounds> caretListener = b ->
1173+
Runnable adjustHighlighterRange = () ->
11721174
{
1173-
if ( b.getMinY() != caretPrevY && lineHighlighter != null )
1175+
if ( lineHighlighter != null )
11741176
{
11751177
int p = getCurrentParagraph();
11761178
int start = getCurrentLineStartInParargraph();
11771179
int end = getCurrentLineEndInParargraph() + 1; // +1 for empty lines
11781180
lineHighlighter.selectRange( p, start, p, end );
1181+
}
1182+
};
1183+
1184+
Consumer<Bounds> caretListener = b ->
1185+
{
1186+
if ( b.getMinY() != caretPrevY ) {
1187+
adjustHighlighterRange.run();
11791188
caretPrevY = b.getMinY();
11801189
}
11811190
};
11821191

1192+
widthProperty().addListener( (ob,ov,nv) -> Platform.runLater( adjustHighlighterRange ) );
11831193
caretBoundsProperty().addListener( (ob,ov,nv) -> nv.ifPresent( caretListener ) );
11841194
getCaretBounds().ifPresent( caretListener );
11851195
selectionSet.add( lineHighlighter );

0 commit comments

Comments
 (0)