on master help sign in
fix: Allow multi-line prompt documentation
2af0432Blaž Hrastnik
helix-term/src/ui/markdown.rs+2−13
@@ -247,19 +247,8 @@ impl Component for Markdown {
247
247
248 // TODO: account for tab width
248 // TODO: account for tab width
249 let max_text_width = (viewport.0 - padding).min(120);
249 let max_text_width = (viewport.0 - padding).min(120);
250− let mut text_width = 0;
250+ let (width, height) = crate::ui::text::required_size(&contents, max_text_width);
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− }
262
251
263− Some((text_width + padding, height))
252+ Some((width + padding * 2, height))
264 }
253 }
265}
254}
helix-term/src/ui/prompt.rs+11−5
@@ -389,12 +389,18 @@ impl Prompt {
389 if let Some(doc) = (self.doc_fn)(&self.line) {
389 if let Some(doc) = (self.doc_fn)(&self.line) {
390 let mut text = ui::Text::new(doc.to_string());
390 let mut text = ui::Text::new(doc.to_string());
391
391
392+ let max_width = BASE_WIDTH * 3;
393+ let padding = 1;
394+
392 let viewport = area;
395 let viewport = area;
396+
397+ let (_width, height) = ui::text::required_size(&text.contents, max_width);
398+
393 let area = viewport.intersection(Rect::new(
399 let area = viewport.intersection(Rect::new(
394 completion_area.x,
400 completion_area.x,
395− completion_area.y.saturating_sub(3),
401+ completion_area.y.saturating_sub(height + padding * 2),
396− BASE_WIDTH * 3,
402+ max_width,
397− 3,
403+ height + padding * 2,
398 ));
404 ));
399
405
400 let background = theme.get("ui.help");
406 let background = theme.get("ui.help");
@@ -402,8 +408,8 @@ impl Prompt {
402
408
403 text.render(
409 text.render(
404 area.inner(&Margin {
410 area.inner(&Margin {
405− vertical: 1,
411+ vertical: padding,
406− horizontal: 1,
412+ horizontal: padding,
407 }),
413 }),
408 surface,
414 surface,
409 cx,
415 cx,
helix-term/src/ui/text.rs+17−1
@@ -4,7 +4,7 @@ use tui::buffer::Buffer as Surface;
4use helix_view::graphics::Rect;
4use helix_view::graphics::Rect;
5
5
6pub struct Text {
6pub struct Text {
7− contents: tui::text::Text<'static>,
7+ pub(crate) contents: tui::text::Text<'static>,
8 size: (u16, u16),
8 size: (u16, u16),
9 viewport: (u16, u16),
9 viewport: (u16, u16),
10}
10}
@@ -49,3 +49,19 @@ impl Component for Text {
49 Some(self.size)
49 Some(self.size)
50 }
50 }
51}
51}
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+}