From e8b626ce18d326c4210f7ca4400b7193b0d87fc9 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 17 Nov 2016 13:16:53 +0100 Subject: [PATCH] fix computing hit character (at mouse press) if padding is set on the paragraph-text To reproduce this, apply a large padding (as below), click at some text in the styled text area and see where the caret is positioned. Without this fix the caret is always some characters right to the click location. .styled-text-area .paragraph-box .paragraph-text { -fx-padding: 0 10em 0 10em; } .styled-text-area .paragraph-box:first-paragraph .paragraph-text { -fx-padding: 10em 10em 0 10em; } .styled-text-area .paragraph-box:last-paragraph .paragraph-text { -fx-padding: 0 10em 10em 10em; } --- richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java index ca7c4fd26..adc744f93 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphBox.java @@ -134,7 +134,8 @@ public CharacterHit hit(Point2D pos) { public CharacterHit hit(double x, double y) { Point2D onScreen = this.localToScreen(x, y); Point2D inText = text.screenToLocal(onScreen); - return text.hit(inText.getX(), inText.getY()); + Insets textInsets = text.getInsets(); + return text.hit(inText.getX() - textInsets.getLeft(), inText.getY() - textInsets.getTop()); } public CaretOffsetX getCaretOffsetX() {