@@ -654,14 +654,14 @@ ParagraphBox.CaretOffsetX getCaretOffsetX() {
654654 return virtualFlow .getHeight ();
655655 }
656656
657- protected CharacterHit hit (ParagraphBox .CaretOffsetX x , TwoDimensional .Position targetLine ) {
657+ CharacterHit hit (ParagraphBox .CaretOffsetX x , TwoDimensional .Position targetLine ) {
658658 int parIdx = targetLine .getMajor ();
659659 ParagraphBox <S , PS > cell = virtualFlow .getCell (parIdx ).getNode ();
660660 CharacterHit parHit = cell .hitTextLine (x , targetLine .getMinor ());
661661 return parHit .offset (getParagraphOffset (parIdx ));
662662 }
663663
664- protected CharacterHit hit (ParagraphBox .CaretOffsetX x , double y ) {
664+ CharacterHit hit (ParagraphBox .CaretOffsetX x , double y ) {
665665 VirtualFlowHit <Cell <Paragraph <S , PS >, ParagraphBox <S , PS >>> hit = virtualFlow .hit (0.0 , y );
666666 if (hit .isBeforeCells ()) {
667667 return CharacterHit .insertionAt (0 );
@@ -677,7 +677,23 @@ protected CharacterHit hit(ParagraphBox.CaretOffsetX x, double y) {
677677 }
678678 }
679679
680- protected CharacterHit hit (double x , double y ) {
680+ /**
681+ * Helpful for determining which letter is at point x, y:
682+ * <pre>
683+ * {@code
684+ * StyledTextArea area = // creation code
685+ * area.addEventHandler(MouseEvent.MOUSE_PRESSED, (MouseEvent e) -> {
686+ * CharacterHit hit = area.hit(e.getX(), e.getY());
687+ * int characterPosition = hit.getInsertionIndex();
688+ *
689+ * // move the caret to that character's position
690+ * area.moveTo(characterPosition, SelectionPolicy.CLEAR);
691+ * }}
692+ * </pre>
693+ * @param x
694+ * @param y
695+ */
696+ public CharacterHit hit (double x , double y ) {
681697 VirtualFlowHit <Cell <Paragraph <S , PS >, ParagraphBox <S , PS >>> hit = virtualFlow .hit (x , y );
682698 if (hit .isBeforeCells ()) {
683699 return CharacterHit .insertionAt (0 );
0 commit comments