Skip to content

Commit

Permalink
Scroll Cursor Visible While Typing (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoolwinter authored Nov 10, 2024
1 parent 3ddd279 commit 2b0c29e
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ extension TextView {
layoutManager.endTransaction()
selectionManager.notifyAfterEdit()
NotificationCenter.default.post(name: Self.textDidChangeNotification, object: self)

// `scrollSelectionToVisible` is a little expensive to call every time. Instead we just check if the first
// selection is entirely visible. `.contains` checks that all points in the rect are inside.
if let selection = selectionManager.textSelections.first, !visibleRect.contains(selection.boundingRect) {
scrollSelectionToVisible()
}
}

/// Replace the characters in a range with a new string.
Expand Down

0 comments on commit 2b0c29e

Please sign in to comment.