From e88a432533eae2b3225b91ef87a1217a9c44fef0 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Fri, 29 Apr 2022 18:12:37 +0200 Subject: [PATCH] feat: approve the popup scroll when resizing the popup --- Kit/module/popup.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Kit/module/popup.swift b/Kit/module/popup.swift index 8757ed1d..fb03f824 100644 --- a/Kit/module/popup.swift +++ b/Kit/module/popup.swift @@ -125,6 +125,7 @@ internal class PopupView: NSView { return CGSize(width: self.frame.width, height: self.frame.height) } private var windowHeight: CGFloat? + private var containerHeight: CGFloat? override init(frame: NSRect) { self.header = HeaderView(frame: NSRect( @@ -140,6 +141,7 @@ internal class PopupView: NSView { height: frame.height - self.header.frame.height - Constants.Popup.margins*2 )) self.windowHeight = NSScreen.main?.visibleFrame.height + self.containerHeight = self.body.documentView?.frame.height super.init(frame: CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.width, height: frame.height)) @@ -213,8 +215,10 @@ internal class PopupView: NSView { width: size.width + (Constants.Popup.margins*2), height: size.height + Constants.Popup.headerHeight + (Constants.Popup.margins*2) ) + let h0 = self.containerHeight ?? 0 - self.windowHeight = NSScreen.main?.visibleFrame.height + self.windowHeight = NSScreen.main?.visibleFrame.height // for height recalculate when appear/disappear + self.containerHeight = self.body.documentView?.frame.height // for scroll diff calculation if let screenHeight = NSScreen.main?.visibleFrame.height, windowSize.height > screenHeight { windowSize.height = screenHeight - Constants.Widget.height isScrollVisible = true @@ -234,7 +238,11 @@ internal class PopupView: NSView { )) if let documentView = self.body.documentView { - documentView.scroll(NSPoint(x: 0, y: self.body.documentVisibleRect.origin.y)) + let diff = h0 - (self.body.documentView?.frame.height ?? 0) + documentView.scroll(NSPoint( + x: 0, + y: self.body.documentVisibleRect.origin.y - (diff < 0 ? diff : 0) + )) } } }