Skip to content

Commit 5c83a9d

Browse files
committed
Fix scrolling on iOS after I changed the placement of the view layout
1 parent 2c837a0 commit 5c83a9d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Sources/SwiftTerm/iOS/iOSTerminalView.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi
177177
var colors: [UIColor?] = Array(repeating: nil, count: 256)
178178
var trueColors: [Attribute.Color:UIColor] = [:]
179179
var transparent = TTColor.transparent ()
180+
private var lastLayoutBounds: CGRect = .zero
180181

181182
// UITextInput support starts
182183
public lazy var tokenizer: UITextInputTokenizer = UITextInputStringTokenizer (textInput: self) // TerminalInputTokenizer()
@@ -1170,8 +1171,25 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi
11701171
}
11711172

11721173
open override func layoutSubviews() {
1173-
processSizeChange(newSize: bounds.size)
1174-
updateCursorPosition()
1174+
super.layoutSubviews()
1175+
guard cellDimension != nil else {
1176+
return
1177+
}
1178+
1179+
let currentBounds = bounds
1180+
let sizeChanged = currentBounds.size != lastLayoutBounds.size
1181+
let originChanged = currentBounds.origin != lastLayoutBounds.origin
1182+
1183+
if sizeChanged {
1184+
processSizeChange(newSize: currentBounds.size)
1185+
updateCursorPosition()
1186+
}
1187+
1188+
if sizeChanged || originChanged {
1189+
setNeedsDisplay(currentBounds)
1190+
}
1191+
1192+
lastLayoutBounds = currentBounds
11751193
}
11761194

11771195
// iOS Keyboard input

0 commit comments

Comments
 (0)