Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make completion window move to top when cursor is below half #322

Merged
merged 3 commits into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) as u16;

let doc = match &option.documentation {
Some(lsp::Documentation::String(contents))
Expand Down Expand Up @@ -289,8 +292,17 @@ 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);
// we want to make sure the cursor is visible (not hidden behind the documentation)
let y = if cursor_pos + view.area.y
>= (cx.editor.tree.area().height - height - 2/* statusline + commandline */)
{
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");
Expand Down
1 change: 0 additions & 1 deletion helix-term/src/ui/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions helix-view/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ impl Tree {
self.focus = key;
}
}

pub fn area(&self) -> Rect {
self.area
}
}

#[derive(Debug)]
Expand Down