Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091012

[Text] No way to distinguish between a hit to the last character and a hit beyond the end of text



    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • 8u20
    • javafx


      When hitting a Text node, there is no way to distinguish between a hit to the trailing edge of the last character and a hit beyond the end of text. Both return a HitInfo

          charIndex: n-1, isLeading: false

      where n is the length of the text. The code to showcase the hit beyond the end of text is below.
      For a hit beyond the end of text, I would suggest to return a HitInfo

          charIndex: n, isLeading: true

      instead. This resolves to the same insertion index, but provides a way to tell apart the two cases.

      Note that making this change also resolves RT-37801.

      I realize that impl_* methods are not public API, but I'm using them in RichTextFX [1] anyway because there's no public API for this functionality. If you are planning/willing to expose more public API on Text/TextFlow, I will be happy to summarize what private API is currently used in RichTextFX.

      import javafx.geometry.Point2D;
      import javafx.scene.text.Text;

      import com.sun.javafx.scene.text.HitInfo;

      public class HitEndOfText {

          public static void main(String[] args) {
              Text text = new Text("foo");
              HitInfo hit = text.impl_hitTestChar(new Point2D(9999, 1));
              // prints: charIndex: 2, isLeading: false
              // expected: charIndex: 3, isLeading: true


      [1] https://github.com/TomasMikula/RichTextFX


        Issue Links



              angorya Andy Goryachev
              tmikula Tomas Mikula
              0 Vote for this issue
              7 Start watching this issue