Polish rendering of inline errors
- Don't soft-wrap - Render multiple lines Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
d0f7e5f075
commit
1875a0e349
3 changed files with 25 additions and 6 deletions
|
@ -285,7 +285,7 @@ impl ProjectDiagnosticsEditor {
|
||||||
diagnostic_blocks.push(DiagnosticBlock::Header(primary.clone()));
|
diagnostic_blocks.push(DiagnosticBlock::Header(primary.clone()));
|
||||||
blocks_to_add.push(BlockProperties {
|
blocks_to_add.push(BlockProperties {
|
||||||
position: header_position,
|
position: header_position,
|
||||||
height: 2,
|
height: primary.message.matches('\n').count() as u8 + 2,
|
||||||
render: diagnostic_header_renderer(
|
render: diagnostic_header_renderer(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
primary.clone(),
|
primary.clone(),
|
||||||
|
|
|
@ -3800,6 +3800,7 @@ pub fn diagnostic_block_renderer(
|
||||||
let mut text_style = settings.style.text.clone();
|
let mut text_style = settings.style.text.clone();
|
||||||
text_style.color = diagnostic_style(diagnostic.severity, is_valid, &settings.style).text;
|
text_style.color = diagnostic_style(diagnostic.severity, is_valid, &settings.style).text;
|
||||||
Text::new(diagnostic.message.clone(), text_style)
|
Text::new(diagnostic.message.clone(), text_style)
|
||||||
|
.with_soft_wrap(false)
|
||||||
.contained()
|
.contained()
|
||||||
.with_margin_left(cx.anchor_x)
|
.with_margin_left(cx.anchor_x)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
@ -3823,7 +3824,11 @@ pub fn diagnostic_header_renderer(
|
||||||
};
|
};
|
||||||
|
|
||||||
Flex::column()
|
Flex::column()
|
||||||
.with_child(Label::new(diagnostic.message.clone(), text_style).boxed())
|
.with_child(
|
||||||
|
Text::new(diagnostic.message.clone(), text_style)
|
||||||
|
.with_soft_wrap(false)
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
.with_child(Label::new(file_path, settings.style.text.clone()).boxed())
|
.with_child(Label::new(file_path, settings.style.text.clone()).boxed())
|
||||||
.boxed()
|
.boxed()
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,6 +14,7 @@ use serde_json::json;
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
text: String,
|
text: String,
|
||||||
style: TextStyle,
|
style: TextStyle,
|
||||||
|
soft_wrap: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LayoutState {
|
pub struct LayoutState {
|
||||||
|
@ -23,13 +24,22 @@ pub struct LayoutState {
|
||||||
|
|
||||||
impl Text {
|
impl Text {
|
||||||
pub fn new(text: String, style: TextStyle) -> Self {
|
pub fn new(text: String, style: TextStyle) -> Self {
|
||||||
Self { text, style }
|
Self {
|
||||||
|
text,
|
||||||
|
style,
|
||||||
|
soft_wrap: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_default_color(mut self, color: Color) -> Self {
|
pub fn with_default_color(mut self, color: Color) -> Self {
|
||||||
self.style.color = color;
|
self.style.color = color;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_soft_wrap(mut self, soft_wrap: bool) -> Self {
|
||||||
|
self.soft_wrap = soft_wrap;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Element for Text {
|
impl Element for Text {
|
||||||
|
@ -54,9 +64,13 @@ impl Element for Text {
|
||||||
self.style.font_size,
|
self.style.font_size,
|
||||||
&[(line.len(), self.style.to_run())],
|
&[(line.len(), self.style.to_run())],
|
||||||
);
|
);
|
||||||
let wrap_boundaries = wrapper
|
let wrap_boundaries = if self.soft_wrap {
|
||||||
.wrap_shaped_line(line, &shaped_line, constraint.max.x())
|
wrapper
|
||||||
.collect::<Vec<_>>();
|
.wrap_shaped_line(line, &shaped_line, constraint.max.x())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
|
||||||
max_line_width = max_line_width.max(shaped_line.width());
|
max_line_width = max_line_width.max(shaped_line.width());
|
||||||
line_count += wrap_boundaries.len() + 1;
|
line_count += wrap_boundaries.len() + 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue