JDK-8341671 : [Text/TextFlow] getCaretInfo
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: graphics
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2024-10-07
  • Updated: 2024-10-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
tbdUnresolved
Related Reports
Cloners :  
Relates :  
Relates :  
Relates :  
Description
The RichTextArea control (JDK-8301121), or any custom control that need to render a custom text caret (such as caret that displays some sort of direction indicator) can benefit from a better public API representing the caret.

Currently, the caret is represented as by array of PathElements in an undocumented fashion; the reverse engineering shows that it's either a single line encoded as [MoveTo,LineTo], or two lines in the case of "split caret" (a situation corresponding to the caret being at the border of RTL and LTR text where the insertion point depends on the type of character that gets inserted).  As a result, the code, both internal and external, is peppered with constructs like 
   if(pathElements.length == 4)
which isn't great.

One possibility is to add a new method to Text / TextFlow:
  public CaretInfo getCaretInfo(int charIndex, boolean leading)

The other is to add this method to the LayoutInfo object obtained from Text/TextFlow added by JDK-8341670.

The CaretInfo class would provide the following data points:
- getLineCount()
- getLineAt(int part)

The RichTextArea requires such a public API in TextFlow only, but we'll basically get the same functionality for Text node for free.

Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jfx/pull/1596 Date: 2024-10-08 16:07:54 +0000
14-10-2024