aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorGokul Soumya2023-02-05 23:24:03 +0000
committerBlaž Hrastnik2023-02-11 07:05:23 +0000
commit425315d7525759545fa9d164434056b435891ad4 (patch)
tree0680f4a76fb13de8f9c0f4e2e7a60689aab534fc /helix-term/src/ui
parent1562b5ce67fbe4239de3b45d21f5853a4c123b99 (diff)
Fix completion doc popup area calculation logic
Earlier the doc popup would draw over the compeltion popup itself and sometimes over the cursor too.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/completion.rs26
1 files changed, 16 insertions, 10 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index 3d354bda..ac434894 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -453,19 +453,25 @@ impl Component for Completion {
}
Rect::new(x, y, doc_width, doc_height)
} else {
- let half = area.height / 2;
- let doc_height = 15.min(half);
- // we want to make sure the cursor is visible (not hidden behind the documentation)
- let y = if cursor_pos + area.y
- >= (cx.editor.tree.area().height - doc_height - 2/* statusline + commandline */)
- {
- 0
+ // Documentation should not cover the cursor or the completion popup
+ // Completion popup could be above or below the current line
+ let avail_height_above = cursor_pos.min(popup_area.top()).saturating_sub(1);
+ let avail_height_below = area
+ .height
+ .saturating_sub(cursor_pos.max(popup_area.bottom()) + 1 /* padding */);
+ let (y, avail_height) = if avail_height_below >= avail_height_above {
+ (
+ area.height.saturating_sub(avail_height_below),
+ avail_height_below,
+ )
} else {
- // -2 to subtract command line + statusline. a bit of a hack, because of splits.
- area.height.saturating_sub(doc_height).saturating_sub(2)
+ (0, avail_height_above)
};
+ if avail_height <= 1 {
+ return;
+ }
- Rect::new(0, y, area.width, doc_height)
+ Rect::new(0, y, area.width, avail_height.min(15))
};
// clear area