@@ -453,19 +453,25 @@ impl Component for Completion {
454 Rect::new(x, y, doc_width, doc_height)
454 Rect::new(x, y, doc_width, doc_height)
456− let half = area.height / 2;
456+ // Documentation should not cover the cursor or the completion popup
457− let doc_height = 15.min(half);
457+ // Completion popup could be above or below the current line
458− // we want to make sure the cursor is visible (not hidden behind the documentation)
458+ let avail_height_above = cursor_pos.min(popup_area.top()).saturating_sub(1);
459− let y = if cursor_pos + area.y
459+ let avail_height_below = area
460− >= (cx.editor.tree.area().height - doc_height - 2/* statusline + commandline */)
460+ .height
461− {
461+ .saturating_sub(cursor_pos.max(popup_area.bottom()) + 1 /* padding */);
462− 0
462+ let (y, avail_height) = if avail_height_below >= avail_height_above {
464+ area.height.saturating_sub(avail_height_below),
464− // -2 to subtract command line + statusline. a bit of a hack, because of splits.
468+ (0, avail_height_above)
465− area.height.saturating_sub(doc_height).saturating_sub(2)
470+ if avail_height <= 1 {
468− Rect::new(0, y, area.width, doc_height)
474+ Rect::new(0, y, area.width, avail_height.min(15))
471 // clear area
477 // clear area