Skip to content

Commit 7e5422f

Browse files
authored
Merge pull request #379 from JordanMartinez/followCaretMadePublic
Make `requestFollowCaret` public and document.
2 parents 19c4480 + a61ea25 commit 7e5422f

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@
103103
* }
104104
* </pre>
105105
*
106+
* <h3>Auto-Scrolling to the Caret</h3>
107+
*
108+
* <p>Every time the underlying {@link EditableStyledDocument} changes via user interaction (e.g. typing) through
109+
* the {@code StyledTextArea}, the area will scroll to insure the caret is kept in view. However, this does not
110+
* occur if changes are done programmatically. For example, let's say the area is displaying the bottom part
111+
* of the area's {@link EditableStyledDocument} and some code changes something in the top part of the document
112+
* that is not currently visible. If there is no call to {@link #requestFollowCaret()} at the end of that code,
113+
* the area will not auto-scroll to that section of the document. The change will occur, and the user will continue
114+
* to see the bottom part of the document as before. If such a call is there, then the area will scroll
115+
* to the top of the document and no longer display the bottom part of it.</p>
116+
*
117+
* <p>Additionally, when overriding the default user-interaction behavior, remember to include a call
118+
* to {@link #requestFollowCaret()}.</p>
119+
*
106120
* <h3>Overriding keyboard shortcuts</h3>
107121
*
108122
* {@code StyledTextArea} uses {@code KEY_TYPED} handler to handle ordinary
@@ -955,7 +969,12 @@ void showCaretAtTop() {
955969
virtualFlow.showAtOffset(parIdx, -y);
956970
}
957971

958-
void requestFollowCaret() {
972+
/**
973+
* If the caret is not visible within the area's view, the area will scroll so that caret
974+
* is visible in the next layout pass. Use this method when you wish to "follow the caret"
975+
* (i.e. auto-scroll to caret) after making a change (add/remove/modify area's segments).
976+
*/
977+
public void requestFollowCaret() {
959978
followCaretRequested = true;
960979
requestLayout();
961980
}

0 commit comments

Comments
 (0)