Skip to content

Commit 2af0432

Browse files
committed
fix: Allow multi-line prompt documentation
1 parent a449156 commit 2af0432

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

helix-term/src/ui/markdown.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,8 @@ impl Component for Markdown {
247247

248248
// TODO: account for tab width
249249
let max_text_width = (viewport.0 - padding).min(120);
250-
let mut text_width = 0;
251-
let mut height = padding;
252-
for content in contents {
253-
height += 1;
254-
let content_width = content.width() as u16;
255-
if content_width > max_text_width {
256-
text_width = max_text_width;
257-
height += content_width / max_text_width;
258-
} else if content_width > text_width {
259-
text_width = content_width;
260-
}
261-
}
250+
let (width, height) = crate::ui::text::required_size(&contents, max_text_width);
262251

263-
Some((text_width + padding, height))
252+
Some((width + padding * 2, height))
264253
}
265254
}

helix-term/src/ui/prompt.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,21 +389,27 @@ impl Prompt {
389389
if let Some(doc) = (self.doc_fn)(&self.line) {
390390
let mut text = ui::Text::new(doc.to_string());
391391

392+
let max_width = BASE_WIDTH * 3;
393+
let padding = 1;
394+
392395
let viewport = area;
396+
397+
let (_width, height) = ui::text::required_size(&text.contents, max_width);
398+
393399
let area = viewport.intersection(Rect::new(
394400
completion_area.x,
395-
completion_area.y.saturating_sub(3),
396-
BASE_WIDTH * 3,
397-
3,
401+
completion_area.y.saturating_sub(height + padding * 2),
402+
max_width,
403+
height + padding * 2,
398404
));
399405

400406
let background = theme.get("ui.help");
401407
surface.clear_with(area, background);
402408

403409
text.render(
404410
area.inner(&Margin {
405-
vertical: 1,
406-
horizontal: 1,
411+
vertical: padding,
412+
horizontal: padding,
407413
}),
408414
surface,
409415
cx,

helix-term/src/ui/text.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tui::buffer::Buffer as Surface;
44
use helix_view::graphics::Rect;
55

66
pub struct Text {
7-
contents: tui::text::Text<'static>,
7+
pub(crate) contents: tui::text::Text<'static>,
88
size: (u16, u16),
99
viewport: (u16, u16),
1010
}
@@ -49,3 +49,19 @@ impl Component for Text {
4949
Some(self.size)
5050
}
5151
}
52+
53+
pub fn required_size(text: &tui::text::Text, max_text_width: u16) -> (u16, u16) {
54+
let mut text_width = 0;
55+
let mut height = 0;
56+
for content in &text.lines {
57+
height += 1;
58+
let content_width = content.width() as u16;
59+
if content_width > max_text_width {
60+
text_width = max_text_width;
61+
height += content_width / max_text_width;
62+
} else if content_width > text_width {
63+
text_width = content_width;
64+
}
65+
}
66+
(text_width, height)
67+
}

0 commit comments

Comments
 (0)