diff options
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/editor.rs | 3 | ||||
-rw-r--r-- | helix-term/src/ui/info.rs | 36 |
2 files changed, 24 insertions, 15 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 496edf42..ffe755e6 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -699,7 +699,8 @@ impl Component for EditorView { match event { Event::Resize(width, height) => { // HAXX: offset the render area height by 1 to account for prompt/commandline - cx.editor.resize(Rect::new(0, 0, width, height - 1)); + cx.editor + .resize(Rect::new(0, 0, width, height.saturating_sub(1))); EventResult::Consumed(None) } Event::Key(key) => { diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs index 36b096db..6e810b86 100644 --- a/helix-term/src/ui/info.rs +++ b/helix-term/src/ui/info.rs @@ -7,24 +7,32 @@ use tui::widgets::{Block, Borders, Widget}; impl Component for Info { fn render(&self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { let style = cx.editor.theme.get("ui.popup"); + + // Calculate the area of the terminal to modify. Because we want to + // render at the bottom right, we use the viewport's width and height + // which evaluate to the most bottom right coordinate. + let (width, height) = (self.width + 2, self.height + 2); + let area = viewport.intersection(Rect::new( + viewport.width.saturating_sub(width), + viewport.height.saturating_sub(height + 2), + width, + height, + )); + surface.clear_with(area, style); + let block = Block::default() .title(self.title.as_str()) .borders(Borders::ALL) .border_style(style); - let Info { width, height, .. } = self; - let (w, h) = (*width + 2, *height + 2); - // -2 to subtract command line + statusline. a bit of a hack, because of splits. - let area = viewport.intersection(Rect::new( - viewport.width.saturating_sub(w), - viewport.height.saturating_sub(h + 2), - w, - h, - )); - surface.clear_with(area, style); - let Rect { x, y, .. } = block.inner(area); - for (y, line) in (y..).zip(self.text.lines()) { - surface.set_string(x, y, line, style); - } + let inner = block.inner(area); block.render(area, surface); + + // Only write as many lines as there are rows available. + for (y, line) in (inner.y..) + .zip(self.text.lines()) + .take(inner.height as usize) + { + surface.set_string(inner.x, y, line, style); + } } } |