diff options
author | Blaž Hrastnik | 2021-05-07 08:31:28 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-05-07 08:31:28 +0000 |
commit | f87dee926a08162f937cb08454c452c7c4dfdb77 (patch) | |
tree | 1beed6d85b287f2058745a00963f79813325ac8d /helix-term/src/ui | |
parent | ff84c8e394391e0f0f05dc8f5281cba17405e5b8 (diff) |
Simplify prompt autocompletion rendering code.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/prompt.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index c59a0eed..f199115f 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -116,18 +116,18 @@ impl Prompt { let max_col = area.width / BASE_WIDTH; let col_height = ((self.completion.len() as u16 + max_col - 1) / max_col); - for i in (3..col_height + 3) { - surface.set_string( - 0, - area.height - i as u16, - " ".repeat(area.width as usize), - text_color, - ); + // completion box area + let area = Rect::new(area.x, area.height - col_height - 2, area.width, col_height); + let background = theme.get("ui.statusline"); + + for y in area.top()..area.bottom() { + for x in area.left()..area.right() { + let cell = surface.get_mut(x, y); + cell.reset(); + cell.set_style(background); + } } - surface.set_style( - Rect::new(0, area.height - col_height - 2, area.width, col_height), - theme.get("ui.statusline"), - ); + for (i, (_range, completion)) in self.completion.iter().enumerate() { let color = if Some(i) == self.completion_selection_index { Style::default().bg(Color::Rgb(104, 60, 232)) @@ -135,14 +135,14 @@ impl Prompt { text_color }; surface.set_stringn( - 1 + col * BASE_WIDTH, - area.height - col_height - 2 + row, + area.x + 1 + col * BASE_WIDTH, + area.y + row, &completion, BASE_WIDTH as usize - 1, color, ); row += 1; - if row > col_height - 1 { + if row > area.height - 1 { row = 0; col += 1; } |