JDK-8304831 : TextFlow.hitTest.insertionIndex incorrect with surrogate pairs
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: jfx19
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-03-23
  • Updated: 2023-06-23
  • Resolved: 2023-06-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
jfx21 b22Fixed
Related Reports
Blocks :  
Blocks :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
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.
Comments
Changeset: c20f6d0f Author: Karthik P K <kpk@openjdk.org> Date: 2023-06-14 05:04:47 +0000 URL: https://git.openjdk.org/jfx/commit/c20f6d0f0133a59a982959ee2e48809f30f3130b
14-06-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jfx/pull/1091 Date: 2023-04-14 07:35:33 +0000
14-04-2023