aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-02-20 05:44:44 +0000
committerBlaž Hrastnik2022-02-20 05:44:44 +0000
commit2af04325d83cd0141400951252574666cffdf1af (patch)
tree5ead25957fa265638d9714e0d7c8568d75261035 /helix-term/src/ui
parenta449156702112a1ee1d11ef2f5495067d801deef (diff)
fix: Allow multi-line prompt documentation
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/markdown.rs15
-rw-r--r--helix-term/src/ui/prompt.rs16
-rw-r--r--helix-term/src/ui/text.rs18
3 files changed, 30 insertions, 19 deletions
diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs
index 6a7b641a..cfb5998c 100644
--- a/helix-term/src/ui/markdown.rs
+++ b/helix-term/src/ui/markdown.rs
@@ -247,19 +247,8 @@ impl Component for Markdown {
// TODO: account for tab width
let max_text_width = (viewport.0 - padding).min(120);
- let mut text_width = 0;
- let mut height = padding;
- for content in contents {
- height += 1;
- let content_width = content.width() as u16;
- if content_width > max_text_width {
- text_width = max_text_width;
- height += content_width / max_text_width;
- } else if content_width > text_width {
- text_width = content_width;
- }
- }
+ let (width, height) = crate::ui::text::required_size(&contents, max_text_width);
- Some((text_width + padding, height))
+ Some((width + padding * 2, height))
}
}
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs
index 18b390dd..7088d6df 100644
--- a/helix-term/src/ui/prompt.rs
+++ b/helix-term/src/ui/prompt.rs
@@ -389,12 +389,18 @@ impl Prompt {
if let Some(doc) = (self.doc_fn)(&self.line) {
let mut text = ui::Text::new(doc.to_string());
+ let max_width = BASE_WIDTH * 3;
+ let padding = 1;
+
let viewport = area;
+
+ let (_width, height) = ui::text::required_size(&text.contents, max_width);
+
let area = viewport.intersection(Rect::new(
completion_area.x,
- completion_area.y.saturating_sub(3),
- BASE_WIDTH * 3,
- 3,
+ completion_area.y.saturating_sub(height + padding * 2),
+ max_width,
+ height + padding * 2,
));
let background = theme.get("ui.help");
@@ -402,8 +408,8 @@ impl Prompt {
text.render(
area.inner(&Margin {
- vertical: 1,
- horizontal: 1,
+ vertical: padding,
+ horizontal: padding,
}),
surface,
cx,
diff --git a/helix-term/src/ui/text.rs b/helix-term/src/ui/text.rs
index caece049..c318052b 100644
--- a/helix-term/src/ui/text.rs
+++ b/helix-term/src/ui/text.rs
@@ -4,7 +4,7 @@ use tui::buffer::Buffer as Surface;
use helix_view::graphics::Rect;
pub struct Text {
- contents: tui::text::Text<'static>,
+ pub(crate) contents: tui::text::Text<'static>,
size: (u16, u16),
viewport: (u16, u16),
}
@@ -49,3 +49,19 @@ impl Component for Text {
Some(self.size)
}
}
+
+pub fn required_size(text: &tui::text::Text, max_text_width: u16) -> (u16, u16) {
+ let mut text_width = 0;
+ let mut height = 0;
+ for content in &text.lines {
+ height += 1;
+ let content_width = content.width() as u16;
+ if content_width > max_text_width {
+ text_width = max_text_width;
+ height += content_width / max_text_width;
+ } else if content_width > text_width {
+ text_width = content_width;
+ }
+ }
+ (text_width, height)
+}