     }
     
 }
+
+
+
+private extension NSWindow {
+    
+    /// calculate window frame for the given contentSize
+    func setFrame(for contentSize: NSSize, flag: Bool = false) {
+        
+        let frameSize = self.frameRect(forContentRect: NSRect(origin: .zero, size: contentSize)).size
+        let frame = NSRect(origin: self.frame.origin, size: frameSize)
+            .offsetBy(dx: 0, dy: self.frame.height - frameSize.height)
+        
+        self.setFrame(frame, display: flag)
+    }
+    
+}

    /// resize window to fit to new view
    private func switchPane(to tabViewItem: NSTabViewItem) {
        
        guard let viewFrame = self.lastFrame ?? tabViewItem.view?.frame else { return assertionFailure() }
        
        // initialize tabView's frame size
        guard let window = self.view.window else {
            self.view.frame = viewFrame
            return
        }
        
        // calculate window frame
        var frame = window.frameRect(forContentRect: viewFrame)
        frame.origin = window.frame.origin
        frame.origin.y += window.frame.height - frame.height
        
        self.view.isHidden = true
        NSAnimationContext.runAnimationGroup({ _ in
            window.animator().setFrame(frame, display: false)
            
        }, completionHandler: { [weak self] in
            self?.view.isHidden = false

        
        super.tabView(tabView, willSelect: tabViewItem)
        
        self.lastFrameSize = tabViewItem?.view?.frame.size
    }
    
    
