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