mirror of
https://github.com/helix-editor/helix.git
synced 2024-09-20 08:05:10 +03:00
fix: Allow multi-line prompt documentation
This commit is contained in:
parent
a449156702
commit
2af04325d8
@ -247,19 +247,8 @@ fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
|
|||||||
|
|
||||||
// TODO: account for tab width
|
// TODO: account for tab width
|
||||||
let max_text_width = (viewport.0 - padding).min(120);
|
let max_text_width = (viewport.0 - padding).min(120);
|
||||||
let mut text_width = 0;
|
let (width, height) = crate::ui::text::required_size(&contents, max_text_width);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Some((text_width + padding, height))
|
Some((width + padding * 2, height))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,12 +389,18 @@ pub fn render_prompt(&self, area: Rect, surface: &mut Surface, cx: &mut Context)
|
|||||||
if let Some(doc) = (self.doc_fn)(&self.line) {
|
if let Some(doc) = (self.doc_fn)(&self.line) {
|
||||||
let mut text = ui::Text::new(doc.to_string());
|
let mut text = ui::Text::new(doc.to_string());
|
||||||
|
|
||||||
|
let max_width = BASE_WIDTH * 3;
|
||||||
|
let padding = 1;
|
||||||
|
|
||||||
let viewport = area;
|
let viewport = area;
|
||||||
|
|
||||||
|
let (_width, height) = ui::text::required_size(&text.contents, max_width);
|
||||||
|
|
||||||
let area = viewport.intersection(Rect::new(
|
let area = viewport.intersection(Rect::new(
|
||||||
completion_area.x,
|
completion_area.x,
|
||||||
completion_area.y.saturating_sub(3),
|
completion_area.y.saturating_sub(height + padding * 2),
|
||||||
BASE_WIDTH * 3,
|
max_width,
|
||||||
3,
|
height + padding * 2,
|
||||||
));
|
));
|
||||||
|
|
||||||
let background = theme.get("ui.help");
|
let background = theme.get("ui.help");
|
||||||
@ -402,8 +408,8 @@ pub fn render_prompt(&self, area: Rect, surface: &mut Surface, cx: &mut Context)
|
|||||||
|
|
||||||
text.render(
|
text.render(
|
||||||
area.inner(&Margin {
|
area.inner(&Margin {
|
||||||
vertical: 1,
|
vertical: padding,
|
||||||
horizontal: 1,
|
horizontal: padding,
|
||||||
}),
|
}),
|
||||||
surface,
|
surface,
|
||||||
cx,
|
cx,
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use helix_view::graphics::Rect;
|
use helix_view::graphics::Rect;
|
||||||
|
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
contents: tui::text::Text<'static>,
|
pub(crate) contents: tui::text::Text<'static>,
|
||||||
size: (u16, u16),
|
size: (u16, u16),
|
||||||
viewport: (u16, u16),
|
viewport: (u16, u16),
|
||||||
}
|
}
|
||||||
@ -49,3 +49,19 @@ fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
|
|||||||
Some(self.size)
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user