From c28ab755ea2eecce2cc083b775881de48a982852 Mon Sep 17 00:00:00 2001 From: Tom Strba <57389842+tomasstrba@users.noreply.github.com> Date: Mon, 12 Feb 2024 11:11:34 +0100 Subject: [PATCH] Cropped tab previews fixed (#2192) Task/Issue URL: https://app.asana.com/0/1177771139624306/1206569585467178/f CC: @mallexxx **Description**: This PR fixes an issue with tab previews being presented outside of the screen bounds. --- .../TabPreview/TabPreviewWindowController.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/DuckDuckGo/TabPreview/TabPreviewWindowController.swift b/DuckDuckGo/TabPreview/TabPreviewWindowController.swift index 61b51932f9..681a6da639 100644 --- a/DuckDuckGo/TabPreview/TabPreviewWindowController.swift +++ b/DuckDuckGo/TabPreview/TabPreviewWindowController.swift @@ -23,6 +23,7 @@ final class TabPreviewWindowController: NSWindowController { static let width: CGFloat = 280 static let padding: CGFloat = 2 + static let bottomPadding: CGFloat = 40 static let delay: CGFloat = 1 private var previewTimer: Timer? @@ -124,8 +125,18 @@ final class TabPreviewWindowController: NSWindowController { guard let window = window else { return } + var topLeftPoint = topLeftPoint + + // Make sure preview is presented within screen + if let screenVisibleFrame = window.screen?.visibleFrame { + topLeftPoint.x = min(topLeftPoint.x, screenVisibleFrame.width - window.frame.width) + + let windowHeight = window.frame.size.height + if topLeftPoint.y <= windowHeight + screenVisibleFrame.origin.y { + topLeftPoint.y = topLeftPoint.y + windowHeight + Self.bottomPadding + } + } - window.setFrame(NSRect(x: 0, y: 0, width: 250, height: 58), display: true) window.setFrameTopLeftPoint(topLeftPoint) }