on master help sign in
Make completion window move to top when cursor is below half
commit980e6023523119676652b49692eb5f844d84d703 authorwojciechkepka <wojtek.kepka@protonmail.com> dateSun 20 Jun 2021, 06:13 (5 years ago) parent34ebe82
2 files changed+11−3
helix-term/src/ui/completion.rs+11−2 helix-term/src/ui/markdown.rs−1
helix-term/src/ui/completion.rs+11−2
@@ -238,6 +238,9 @@ impl Component for Completion {
238238 .language()
239239 .and_then(|scope| scope.strip_prefix("source."))
240240 .unwrap_or("");
241+ let cursor_pos = doc.selection(view.id).cursor();
242+ let cursor_pos =
243+ helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row - view.first_line;
241244
242245 let doc = match &option.documentation {
243246 Some(lsp::Documentation::String(contents))
@@ -289,8 +292,14 @@ impl Component for Completion {
289292
290293 let half = area.height / 2;
291294 let height = 15.min(half);
292− // -2 to subtract command line + statusline. a bit of a hack, because of splits.
293− let area = Rect::new(0, area.height - height - 2, area.width, height);
295+ let y = if cursor_pos > half as usize {
296+ 0
297+ } else {
298+ // -2 to subtract command line + statusline. a bit of a hack, because of splits.
299+ area.height.saturating_sub(height).saturating_sub(2)
300+ };
301+
302+ let area = Rect::new(0, y, area.width, height);
294303
295304 // clear area
296305 let background = cx.editor.theme.get("ui.popup");
helix-term/src/ui/markdown.rs−1
@@ -162,7 +162,6 @@ fn parse<'a>(
162162 }
163163 }
164164 Event::Code(text) | Event::Html(text) => {
165− log::warn!("code {:?}", text);
166165 let mut span = to_span(text);
167166 span.style = code_style;
168167 spans.push(span);