This issue can be thought of as a subset of JDK-8092278 that can hopefully be implemented much sooner. The scope of this issue is solely hit test API (i.e. given the (x, y) coordinates, give me the position in text), *not* selection API a la DOM Range.
It was possible to work around the lack of a hit test API using reflection and private (com.sun.*) API, but this workaround will stop working in JDK 9.
A hit test must be able to determine the character that was hit, if any, and the insertion index (for caret positioning).
I propose adding the following method to TextFlow:
public HitInfo hitTest(double x, double y);
where HitInfo has the following interface
public class HitInfo {
public OptionalInt getCharacterIndex();
public int getInsertionIndex();
}
getCharacterIndex() returning OptionalInt allows to distinguish whether a character was hit at all (JDK-8091012).
getInsertionIndex() should take character clusters (JDK-8092327 point 2.) into account.
I implemented the hit test method in RichTextFX based on Felipe's suggestion (https://bugs.openjdk.java.net/browse/JDK-8091012?focusedCommentId=13795297&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13795297). It does not handle clusters, but I am happy to contribute the code.
It was possible to work around the lack of a hit test API using reflection and private (com.sun.*) API, but this workaround will stop working in JDK 9.
A hit test must be able to determine the character that was hit, if any, and the insertion index (for caret positioning).
I propose adding the following method to TextFlow:
public HitInfo hitTest(double x, double y);
where HitInfo has the following interface
public class HitInfo {
public OptionalInt getCharacterIndex();
public int getInsertionIndex();
}
getCharacterIndex() returning OptionalInt allows to distinguish whether a character was hit at all (JDK-8091012).
getInsertionIndex() should take character clusters (JDK-8092327 point 2.) into account.
I implemented the hit test method in RichTextFX based on Felipe's suggestion (https://bugs.openjdk.java.net/browse/JDK-8091012?focusedCommentId=13795297&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13795297). It does not handle clusters, but I am happy to contribute the code.
- relates to
-
JDK-8136971 Review the new TextPosInfo API
-
- Resolved
-
-
JDK-8136573 Review (and possibly make public) candidate API from private APIs
-
- Resolved
-
-
JDK-8091012 [Text] No way to distinguish between a hit to the last character and a hit beyond the end of text
-
- Open
-
-
JDK-8092327 [Text] Add API to count chars in a cluster
-
- Open
-
-
JDK-8092278 Text should have API for selecting group of characters based on their position similar to the DOM's Range.
-
- Closed
-