Skip to content

Commit 2b0c29e

Browse files
Scroll Cursor Visible While Typing (#55)
1 parent 3ddd279 commit 2b0c29e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/CodeEditTextView/TextView/TextView+ReplaceCharacters.swift

+6
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)