On Fri, 5 Dec 2025 17:09:34 GMT, Andy Goryachev <[email protected]> wrote:
>> This PR addresses the user feedback: >> >> In RichParagraph you have a note to make getSegments() public. It would be >> helpful if it was. >> >> >> The problem being solved here is to allow the developers to easily add >> functionality to the existing `RichTextModel` (and its storage >> implementation) without creating a new model from scratch. >> >> This is done in two parts: >> >> 1. Allowing the custom model to alter the paragraph by giving access to its >> Builder via a new protected method >> >> >> protected RichParagraph.Builder buildParagraph(int index) >> >> >> 2. Adding two methods that give access to the segments in the >> `RichParagraph` and `RichParagraph.Builder` classes: >> >> - getSegmentCount() >> - getSegment(int index) >> >> NOTE: Even though returning an (immutable) List might be considered "more >> useful", doing so would necessitate creating a copy - something I do want to >> avoid. > > Andy Goryachev has updated the pull request with a new target base due to a > merge or a rebase. The pull request now contains eight commits: > > - Merge branch 'master' into 8371070.enhance > - npe > - merge > - Merge branch 'master' into 8371070.enhance > - Merge branch 'master' into 8371070.enhance > - Merge branch 'master' into 8371070.enhance > - test > - expose segments There is an alternative. Instead of adding `getSegmentCount()` / `getSegment(int)` methods to the `RichParagraph`, we might expose the `RichParagraph.Builder` used to build the paragraph by the model via protected RichParagraph.Builder buildParagraph(int index) method added to the `RichTextModel` class (and possibly to the `CodeTextModel` as well). Doing so would allow custom models easily add custom attributes that generate highlights or wavy underlines (which might span segments or apply to partial segments), as can be seen in the following example: https://github.com/andy-goryachev-oracle/Test/blob/paragraph.enhancements/src/goryachev/research/RichTextArea_CustomModel_8366198.java <img width="592" height="316" alt="Screenshot 2025-12-09 at 10 48 20" src="https://github.com/user-attachments/assets/47acd986-6f5d-471a-94e1-ad1b4c0f3b32" /> Exposing the builder would also necessitate adding `getSegmentCount()` / `getSegment(int)` methods to the `RichParagraph.Builder`. What do you think? ------------- PR Comment: https://git.openjdk.org/jfx/pull/1966#issuecomment-3634052681
