File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -14,26 +14,25 @@ extension TextView {
14
14
15
15
/// Scrolls the upmost selection to the visible rect if `scrollView` is not `nil`.
16
16
public func scrollSelectionToVisible( ) {
17
- guard let scrollView, let selection = getSelection ( ) else {
17
+ guard let scrollView else {
18
18
return
19
19
}
20
20
21
- let offsetToScrollTo = offsetNotPivot ( selection)
22
-
23
21
// There's a bit of a chicken-and-the-egg issue going on here. We need to know the rect to scroll to, but we
24
22
// can't know the exact rect to make visible without laying out the text. Then, once text is laid out the
25
23
// selection rect may be different again. To solve this, we loop until the frame doesn't change after a layout
26
24
// pass and scroll to that rect.
27
25
28
26
var lastFrame : CGRect = . zero
29
- while let boundingRect = layoutManager . rectForOffset ( offsetToScrollTo ) , lastFrame != boundingRect {
27
+ while let boundingRect = getSelection ( ) ? . boundingRect , lastFrame != boundingRect {
30
28
lastFrame = boundingRect
31
29
layoutManager. layoutLines ( )
32
30
selectionManager. updateSelectionViews ( )
33
31
selectionManager. drawSelections ( in: visibleRect)
34
32
}
35
33
if lastFrame != . zero {
36
34
scrollView. contentView. scrollToVisible ( lastFrame)
35
+ scrollView. reflectScrolledClipView ( scrollView. contentView)
37
36
}
38
37
}
39
38
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ public class CEUndoManager: UndoManager {
85
85
textView. textStorage. endEditing ( )
86
86
87
87
updateSelectionsForMutations ( mutations: item. mutations. map { $0. mutation } )
88
+ textView. scrollSelectionToVisible ( )
88
89
89
90
NotificationCenter . default. post ( name: . NSUndoManagerDidUndoChange, object: self )
90
91
redoStack. append ( item)
@@ -112,6 +113,7 @@ public class CEUndoManager: UndoManager {
112
113
textView. textStorage. endEditing ( )
113
114
114
115
updateSelectionsForMutations ( mutations: item. mutations. map { $0. inverse } )
116
+ textView. scrollSelectionToVisible ( )
115
117
116
118
NotificationCenter . default. post ( name: . NSUndoManagerDidRedoChange, object: self )
117
119
undoStack. append ( item)
You can’t perform that action at this time.
0 commit comments