added nullspace diagnostic rendering

pull/11409/head
Stephen Broadley 3 weeks ago committed by Stephen Broadley
parent 8c3e9b1a03
commit 6962ca6830

@ -773,8 +773,24 @@ impl EditorView {
let info = theme.get("info"); let info = theme.get("info");
let hint = theme.get("hint"); let hint = theme.get("hint");
let width = 50.min(viewport.width);
// place it in the nullspace if we have room, and on the same
// line as the cursor to make it easier to read
//
let gutter_size = view.gutter_offset(doc);
let left_nullspace = viewport.left() - view.area.left() - gutter_size;
let use_nullspace = left_nullspace > width;
let background_style = if use_nullspace {
theme
.try_get("ui.nullspace")
.unwrap_or(theme.get("ui.background"))
} else {
theme.get("ui.background")
};
let mut lines = Vec::new(); let mut lines = Vec::new();
let background_style = theme.get("ui.background");
for diagnostic in diagnostics { for diagnostic in diagnostics {
let style = Style::reset() let style = Style::reset()
.patch(background_style) .patch(background_style)
@ -800,12 +816,26 @@ impl EditorView {
let paragraph = Paragraph::new(&text) let paragraph = Paragraph::new(&text)
.alignment(Alignment::Right) .alignment(Alignment::Right)
.wrap(Wrap { trim: true }); .wrap(Wrap { trim: true });
let width = 100.min(viewport.width); let height = 15.min(viewport.height).min(text.lines.len() as u16);
let height = 15.min(viewport.height);
paragraph.render( // decide where this diagnostic is gonna get rendered
Rect::new(viewport.right() - width, viewport.y + 1, width, height), //
surface, let mut diag_x = viewport.right() - width;
); let mut diag_y = viewport.top() + 1;
if use_nullspace {
if let Some(pos) = view.screen_coords_at_pos(doc, doc.text().slice(..), cursor) {
diag_x = viewport.left() - width - gutter_size - 2;
diag_y = pos.row as u16 + viewport.top();
// correct for OOB
if diag_y + height > viewport.bottom() {
diag_y -= (diag_y + height) - viewport.bottom();
}
}
}
paragraph.render(Rect::new(diag_x, diag_y, width, height), surface);
} }
/// Apply the highlighting on the lines where a cursor is active /// Apply the highlighting on the lines where a cursor is active
@ -828,7 +858,7 @@ impl EditorView {
let primary_style = theme.get("ui.cursorline.primary"); let primary_style = theme.get("ui.cursorline.primary");
let secondary_style = theme.get("ui.cursorline.secondary"); let secondary_style = theme.get("ui.cursorline.secondary");
let viewport = view.area; let viewport = view.inner_area(doc);
move |renderer: &mut TextRenderer, pos: LinePos| { move |renderer: &mut TextRenderer, pos: LinePos| {
let area = Rect::new(viewport.x, pos.visual_line, viewport.width, 1); let area = Rect::new(viewport.x, pos.visual_line, viewport.width, 1);

Loading…
Cancel
Save