@@ -224,6 +224,11 @@ enum UpdateLocationStrategy {
224224 guard let selectionFrame = UpdateLocationStrategy
225225 . getSelectionFirstLineFrame ( editor: editor) else { return nil }
226226
227+ // hide it when the line of code is outside of the editor visible rect
228+ if selectionFrame. maxY < editorFrame. minY || selectionFrame. minY > editorFrame. maxY {
229+ return nil
230+ }
231+
227232 let proposedY = mainScreen. frame. height - selectionFrame. maxY
228233 let proposedX = selectionFrame. maxX - 40
229234 let maxY = max (
@@ -235,7 +240,11 @@ enum UpdateLocationStrategy {
235240 activeScreen. frame. maxY - 4
236241 )
237242
238- let alignPanelTopToAnchor = y - Style. inlineSuggestionMaxHeight >= activeScreen. frame. minY
243+ // align panel to top == place under the selection frame.
244+ // we initially try to place it at the bottom side, but if there is no enough space
245+ // we move it to the top of the selection frame.
246+ let alignPanelTopToAnchor = y - Style. inlineSuggestionMaxHeight
247+ >= activeScreen. frame. minY
239248
240249 let caseIgnoreCompletionPanel = {
241250 ( alignPanelTopToAnchor: Bool ) -> WidgetLocation . PanelLocation ? in
@@ -246,7 +255,7 @@ enum UpdateLocationStrategy {
246255 return activeScreen. frame. maxX - Style. inlineSuggestionMinWidth
247256 } ( )
248257 if alignPanelTopToAnchor {
249- // case: present below selection
258+ // case: present under selection
250259 return . init(
251260 frame: . init(
252261 x: x,
@@ -257,6 +266,7 @@ enum UpdateLocationStrategy {
257266 alignPanelTop: alignPanelTopToAnchor
258267 )
259268 } else {
269+ // case: present above selection
260270 return . init(
261271 frame: . init(
262272 x: x,
@@ -275,8 +285,10 @@ enum UpdateLocationStrategy {
275285
276286 switch ( completionPanelBelowCursor, alignPanelTopToAnchor) {
277287 case ( true , false ) , ( false , true ) :
288+ // case: different position, place the suggestion as it should be
278289 return caseIgnoreCompletionPanel ( alignPanelTopToAnchor)
279290 case ( true , true ) , ( false , false ) :
291+ // case: same position, place the suggestion next to the completion panel
280292 let y = completionPanelBelowCursor
281293 ? y - Style. inlineSuggestionMaxHeight
282294 : y + selectionFrame. height - Style. widgetPadding
@@ -303,6 +315,7 @@ enum UpdateLocationStrategy {
303315 alignPanelTop: alignPanelTopToAnchor
304316 )
305317 }
318+ // case: no enough horizontal space, place the suggestion on the other side
306319 return caseIgnoreCompletionPanel ( !alignPanelTopToAnchor)
307320 }
308321 }
0 commit comments