aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwojciechkepka2021-06-20 04:13:44 +0000
committerBlaž Hrastnik2021-06-20 10:59:26 +0000
commit980e6023523119676652b49692eb5f844d84d703 (patch)
tree75eade8169722bfaec5e419270d91fe3bc651c7d
parent34ebe8265468df755598dde2ec79c249b581ba97 (diff)
Make completion window move to top when cursor is below half
-rw-r--r--helix-term/src/ui/completion.rs13
-rw-r--r--helix-term/src/ui/markdown.rs1
2 files changed, 11 insertions, 3 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index 88a71534..f4d882de 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -238,6 +238,9 @@ impl Component for Completion {
.language()
.and_then(|scope| scope.strip_prefix("source."))
.unwrap_or("");
+ let cursor_pos = doc.selection(view.id).cursor();
+ let cursor_pos =
+ helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row - view.first_line;
let doc = match &option.documentation {
Some(lsp::Documentation::String(contents))
@@ -289,8 +292,14 @@ impl Component for Completion {
let half = area.height / 2;
let height = 15.min(half);
- // -2 to subtract command line + statusline. a bit of a hack, because of splits.
- let area = Rect::new(0, area.height - height - 2, area.width, height);
+ let y = if cursor_pos > half as usize {
+ 0
+ } else {
+ // -2 to subtract command line + statusline. a bit of a hack, because of splits.
+ area.height.saturating_sub(height).saturating_sub(2)
+ };
+
+ let area = Rect::new(0, y, area.width, height);
// clear area
let background = cx.editor.theme.get("ui.popup");
diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs
index 91086f7b..75e2f4b4 100644
--- a/helix-term/src/ui/markdown.rs
+++ b/helix-term/src/ui/markdown.rs
@@ -162,7 +162,6 @@ fn parse<'a>(
}
}
Event::Code(text) | Event::Html(text) => {
- log::warn!("code {:?}", text);
let mut span = to_span(text);
span.style = code_style;
spans.push(span);