@@ -186,7 +186,7 @@ public final class SuggestionWidgetController {
186186 for await notification in notifications {
187187 guard let self else { return }
188188 try Task . checkCancellation ( )
189- self . updateWindowLocation ( )
189+ self . updateWindowLocation ( animated : false )
190190
191191 if notification. name == kAXFocusedUIElementChangedNotification {
192192 guard let fileURL = try ? await Environment . fetchCurrentFileURL ( ) ,
@@ -211,7 +211,7 @@ public final class SuggestionWidgetController {
211211 ///
212212 /// - note: It's possible to get the scroll view's postion by getting position on the focus
213213 /// element.
214- private func updateWindowLocation( ) {
214+ private func updateWindowLocation( animated : Bool = false ) {
215215 func hide( ) {
216216 panelWindow. alphaValue = 0
217217 widgetWindow. alphaValue = 0
@@ -246,26 +246,60 @@ public final class SuggestionWidgetController {
246246 let screen = NSScreen . screens. first
247247 let frame = CGRect ( origin: position, size: size)
248248 if foundSize, foundPosition, let screen {
249- let anchorFrame = CGRect (
250- x: frame. maxX - 4 - Style. widgetWidth,
251- y: screen. frame. height - frame. minY - Style. widgetHeight - 4 ,
249+ let proposedAnchorFrameOnTheRightSide = CGRect (
250+ x: frame. maxX - Style . widgetPadding - Style. widgetWidth,
251+ y: max ( screen. frame. height - frame. maxY + Style. widgetPadding , 4 ) ,
252252 width: Style . widgetWidth,
253253 height: Style . widgetHeight
254254 )
255- widgetWindow. setFrame ( anchorFrame, display: false )
256255
257- let proposedPanelX = anchorFrame. maxX + 8
256+ let proposedPanelX = proposedAnchorFrameOnTheRightSide. maxX + Style
257+ . widgetPadding * 2
258258 let putPanelToTheRight = screen. frame. maxX > proposedPanelX + Style. panelWidth
259259
260- let panelFrame = CGRect (
261- x: putPanelToTheRight ? proposedPanelX : anchorFrame. maxX - Style
262- . panelWidth,
263- y: putPanelToTheRight ? anchorFrame. minY - Style. panelHeight + Style
264- . widgetHeight : anchorFrame. minY - Style. panelHeight - 4 ,
265- width: Style . panelWidth,
266- height: Style . panelHeight
267- )
268- panelWindow. setFrame ( panelFrame, display: false )
260+ if putPanelToTheRight {
261+ let anchorFrame = proposedAnchorFrameOnTheRightSide
262+ let panelFrame = CGRect (
263+ x: proposedPanelX,
264+ y: anchorFrame. minY,
265+ width: Style . panelWidth,
266+ height: Style . panelHeight
267+ )
268+ widgetWindow. setFrame ( anchorFrame, display: false , animate: animated)
269+ panelWindow. setFrame ( panelFrame, display: false , animate: animated)
270+ } else {
271+ let proposedAnchorFrameOnTheLeftSide = CGRect (
272+ x: frame. minX + Style. widgetPadding + Style. widgetWidth,
273+ y: proposedAnchorFrameOnTheRightSide. origin. y,
274+ width: Style . widgetWidth,
275+ height: Style . widgetHeight
276+ )
277+ let proposedPanelX = proposedAnchorFrameOnTheLeftSide. minX - Style
278+ . widgetPadding * 2 - Style. panelWidth
279+ let putAnchorToTheLeft = proposedPanelX > screen. frame. minX
280+
281+ if putAnchorToTheLeft {
282+ let anchorFrame = proposedAnchorFrameOnTheLeftSide
283+ let panelFrame = CGRect (
284+ x: proposedPanelX,
285+ y: anchorFrame. minY,
286+ width: Style . panelWidth,
287+ height: Style . panelHeight
288+ )
289+ widgetWindow. setFrame ( anchorFrame, display: false , animate: animated)
290+ panelWindow. setFrame ( panelFrame, display: false , animate: animated)
291+ } else {
292+ let anchorFrame = proposedAnchorFrameOnTheRightSide
293+ let panelFrame = CGRect (
294+ x: anchorFrame. maxX - Style. panelWidth,
295+ y: anchorFrame. maxY + Style. widgetPadding,
296+ width: Style . panelWidth,
297+ height: Style . panelHeight
298+ )
299+ widgetWindow. setFrame ( anchorFrame, display: false , animate: animated)
300+ panelWindow. setFrame ( panelFrame, display: false , animate: animated)
301+ }
302+ }
269303
270304 panelWindow. alphaValue = 1
271305 widgetWindow. alphaValue = 1
0 commit comments