## Summary

Add a new method to the `RichTextArea` class and its sibling `CodeArea` to 
allow for
programmatic positioning of the caret within the viewport.



## Problem

It is impossible to scroll the view to place the caret at a specific position 
using existing public APIs.
This feature has been requested in [0], for example.



## Solution

The solution involves adding a new method which scrolls the view (without 
changing the caret position within the text).



## Specification



    /**
     * Scrolls the caret to the location within the viewport determined by the 
fraction alongside each axis.
     * For example, calling this method with (0, 0.5) positions the caret at 
the left side halfway down vertically.
     * Both parameters are clamped to be within [0.0 ... 1.0] range, {@link 
Double#NaN} is treated as 0.0.
     * The {@code horFraction} parameter is ignored when {@link 
#wrapTextProperty()} is {@code true}.
     * This method is a no-op when the skin or the selection is {@code null}.
     *
     * @param horFraction the fraction of the viewport width
     * @param verFraction the fraction of the viewport height
     * @since 28
     */
    public final void scrollCaretInView(double horFraction, double verFraction)



## Testing

`RichTextAreaDemoApp` adds a "Scroll to" button to demonstrate the feature.



## References

- [0] [JabRef issue #17771](https://github.com/JabRef/jabref/issues/17771)




---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - to visible
 - height
 - whitespace
 - Merge remote-tracking branch 'origin/master' into 8380073.scroll
 - test
 - scroll caret to position

Changes: https://git.openjdk.org/jfx/pull/2376/files
  Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2376&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8380073
  Stats: 183 lines in 5 files changed: 183 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jfx/pull/2376.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/2376/head:pull/2376

PR: https://git.openjdk.org/jfx/pull/2376

Reply via email to