Skip to content

Commit f3d438b

Browse files
committed
Fix SplitView layout during window resizing under AppKitBackend
The layout went a bit bonkers during window resizing before this fix. When the resize required the panes to resize they just wouldn't and the split view would end up bigger than the window and flicker back and forth randomly as you continued resizing.
1 parent 64eeadc commit f3d438b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ class NSSplitViewResizingDelegate: NSObject, NSSplitViewDelegate {
653653
var leadingWidth = 0
654654
var minimumLeadingWidth = 0
655655
var maximumLeadingWidth = 0
656+
var isFirstUpdate = true
656657

657658
func setResizeHandler(_ handler: @escaping (_ paneWidths: [Int]) -> Void) {
658659
resizeHandler = handler
@@ -693,7 +694,15 @@ class NSSplitViewResizingDelegate: NSObject, NSSplitViewDelegate {
693694

694695
func splitView(_ splitView: NSSplitView, resizeSubviewsWithOldSize oldSize: NSSize) {
695696
splitView.adjustSubviews()
696-
splitView.setPosition(200, ofDividerAt: 0)
697+
698+
if isFirstUpdate {
699+
splitView.setPosition(max(200, CGFloat(minimumLeadingWidth)), ofDividerAt: 0)
700+
isFirstUpdate = false
701+
} else {
702+
// Magic! Thanks https://stackoverflow.com/a/30494691. This one line fixed all
703+
// of the split view resizing issues.
704+
splitView.setPosition(splitView.subviews[0].frame.width, ofDividerAt: 0)
705+
}
697706
}
698707
}
699708

0 commit comments

Comments
 (0)