Skip to content

Commit 405e3a4

Browse files
committed
Scroll Cursor Visible While Typing
1 parent 3ddd279 commit 405e3a4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/CodeEditTextView/TextView/TextView+ReplaceCharacters.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ extension TextView {
4242
layoutManager.endTransaction()
4343
selectionManager.notifyAfterEdit()
4444
NotificationCenter.default.post(name: Self.textDidChangeNotification, object: self)
45+
46+
// `scrollSelectionToVisible` is a little expensive to call every time. Instead we just check if the first
47+
// selection is entirely visible. `.contains` checks that all points in the rect are inside.
48+
if let selection = selectionManager.textSelections.first, !visibleRect.contains(selection.boundingRect) {
49+
scrollSelectionToVisible()
50+
}
4551
}
4652

4753
/// Replace the characters in a range with a new string.

0 commit comments

Comments
 (0)