From 9bc0dfc6f3dad59e815416d398713210bacdd14e Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 11 Jan 2025 19:16:02 -0800 Subject: [PATCH] Window now always appears in the same location. --- src/SearchViewController.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/SearchViewController.swift b/src/SearchViewController.swift index 783c984..631997f 100644 --- a/src/SearchViewController.swift +++ b/src/SearchViewController.swift @@ -253,10 +253,11 @@ class SearchViewController: NSViewController, NSTextFieldDelegate, keyboardEvents?.start() - // TODO: This doesn't play well when the window is expanded with - // search results, causing it to reappear in a slightly - // above usual position. - view.window?.center() + if let win = view.window, let scrn = NSScreen.main { + let x = (scrn.visibleFrame.size.width / 2) - (win.frame.size.width / 2) + let y = (scrn.visibleFrame.size.height * 0.9) - win.frame.size.height + view.window?.setFrameOrigin(NSPoint(x: x, y: y)) + } view.window?.makeFirstResponder(searchInput) // searchInput should select all text whenever window appears.