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

TextFlow.hitTest.insertionIndex incorrect with surrogate pairs

XMLWordPrintable

    • b22

      The expectation is that TextFlow.hitTest() and Text.hitTest() produce essentially the same result regardless of the underlying text.

      In reality, TextFlow implementation is buggy when it comes to handling of the surrogate pairs, as it requires character break iterator to skip over characters that represent a single unicode code point (see HitInfo.getInsertionIndex()). However, the text field is null, so the correct logic can not be implemented.

      Also, it appears there is weird behavior in the Text.hitTest() inside a large emoji symbol: as one can see in the attached video: Text.insertionIndex() goes 0, 2, 1, 2 when moving the mouse across the symbol from the left edge to the right edge. (please create a new ticket if this is a separate issue).

      A workaround might to scan TextFlow children to pick the right Text instance and then use its hitTest() method, though it might require a linear search and cause performance issues with long text flows.
      edit: the workaround does not quite work, the reported position is incorrect in the case when multiple Text instances are added to the TextFlow.

      SCCE to follow.

            kpk Karthik P K
            angorya Andy Goryachev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: