feat: figure out how to draw stuff at the end of lines
This commit is contained in:
parent
8cfa56b643
commit
1ac4e51932
5 changed files with 132 additions and 3 deletions
|
@ -37,6 +37,6 @@ pub fn setup(config: Arc<ArcSwap<Config>>) -> Handlers {
|
|||
auto_save::register_hooks(&handlers);
|
||||
diagnostics::register_hooks(&handlers);
|
||||
snippet::register_hooks(&handlers);
|
||||
blame::register_hooks(&handlers);
|
||||
// blame::register_hooks(&handlers);
|
||||
handlers
|
||||
}
|
||||
|
|
|
@ -201,6 +201,15 @@ impl EditorView {
|
|||
inline_diagnostic_config,
|
||||
config.end_of_line_diagnostics,
|
||||
));
|
||||
log::error!("{}", primary_cursor);
|
||||
// if config.vcs.blame {
|
||||
// decorations.add_decoration(text_decorations::blame::EolBlame::new(
|
||||
// doc,
|
||||
// theme,
|
||||
// primary_cursor,
|
||||
// "hello world".to_string(),
|
||||
// ));
|
||||
// }
|
||||
render_document(
|
||||
surface,
|
||||
inner,
|
||||
|
|
|
@ -8,6 +8,7 @@ use crate::ui::document::{LinePos, TextRenderer};
|
|||
|
||||
pub use diagnostics::InlineDiagnostics;
|
||||
|
||||
pub mod blame;
|
||||
mod diagnostics;
|
||||
|
||||
/// Decorations are the primary mechanism for extending the text rendering.
|
||||
|
|
92
helix-term/src/ui/text_decorations/blame.rs
Normal file
92
helix-term/src/ui/text_decorations/blame.rs
Normal file
|
@ -0,0 +1,92 @@
|
|||
#![allow(dead_code, unused_variables, unused_mut)]
|
||||
|
||||
use helix_core::doc_formatter::FormattedGrapheme;
|
||||
use helix_core::Position;
|
||||
|
||||
use helix_view::theme::Style;
|
||||
use helix_view::{Document, Theme};
|
||||
|
||||
use crate::ui::document::{LinePos, TextRenderer};
|
||||
use crate::ui::text_decorations::Decoration;
|
||||
|
||||
pub struct EolBlame<'a> {
|
||||
message: String,
|
||||
doc: &'a Document,
|
||||
cursor: usize,
|
||||
style: Style,
|
||||
}
|
||||
|
||||
impl<'a> EolBlame<'a> {
|
||||
pub fn new(doc: &'a Document, theme: &Theme, cursor: usize, message: String) -> Self {
|
||||
EolBlame {
|
||||
style: theme.get("ui.virtual.blame"),
|
||||
message,
|
||||
doc,
|
||||
cursor,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoration for EolBlame<'_> {
|
||||
// fn decorate_line(&mut self, renderer: &mut TextRenderer, pos: LinePos) {
|
||||
// // renderer.draw_dec
|
||||
// // ration_grapheme(grapheme, style, row, col)
|
||||
// let col_off = 50;
|
||||
// }
|
||||
|
||||
fn render_virt_lines(
|
||||
&mut self,
|
||||
renderer: &mut TextRenderer,
|
||||
pos: LinePos,
|
||||
virt_off: Position,
|
||||
) -> Position {
|
||||
let row = pos.visual_line;
|
||||
let col = virt_off.col as u16;
|
||||
// if col != self.cursor as u16 {
|
||||
// return Position::new(0, 0);
|
||||
// }
|
||||
let style = self.style;
|
||||
let width = renderer.viewport.width;
|
||||
let start_col = col - renderer.offset.col as u16;
|
||||
// start drawing the git blame 1 space after the end of the line
|
||||
let draw_col = col + 1;
|
||||
|
||||
let end_col = renderer
|
||||
.column_in_bounds(draw_col as usize, 1)
|
||||
.then(|| {
|
||||
renderer
|
||||
.set_string_truncated(
|
||||
renderer.viewport.x + draw_col,
|
||||
row,
|
||||
&self.message,
|
||||
width.saturating_sub(draw_col) as usize,
|
||||
|_| self.style,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.0
|
||||
})
|
||||
.unwrap_or(start_col);
|
||||
log::error!("cursor: {}, row: {row}, col: {col}, start_col: {start_col}, draw_col: {draw_col}, end_col: {end_col}", self.cursor);
|
||||
|
||||
let col_off = end_col - start_col;
|
||||
|
||||
Position::new(0, col_off as usize)
|
||||
}
|
||||
|
||||
// fn reset_pos(&mut self, _pos: usize) -> usize {
|
||||
// usize::MAX
|
||||
// }
|
||||
|
||||
// fn skip_concealed_anchor(&mut self, conceal_end_char_idx: usize) -> usize {
|
||||
// self.reset_pos(conceal_end_char_idx)
|
||||
// }
|
||||
|
||||
// fn decorate_grapheme(
|
||||
// &mut self,
|
||||
// _renderer: &mut TextRenderer,
|
||||
// _grapheme: &FormattedGrapheme,
|
||||
// ) -> usize {
|
||||
// usize::MAX
|
||||
// }
|
||||
}
|
|
@ -271,14 +271,41 @@ impl Decoration for InlineDiagnostics<'_> {
|
|||
DiagnosticFilter::Disable => None,
|
||||
};
|
||||
if let Some((eol_diagnostic, _)) = eol_diagnostic {
|
||||
let mut renderer = Renderer {
|
||||
let renderer = Renderer {
|
||||
renderer,
|
||||
first_row: pos.visual_line,
|
||||
row: pos.visual_line,
|
||||
config: &self.state.config,
|
||||
styles: &self.styles,
|
||||
};
|
||||
col_off = renderer.draw_eol_diagnostic(eol_diagnostic, pos.visual_line, virt_off.col);
|
||||
// let ref mut this = renderer;
|
||||
let row = pos.visual_line;
|
||||
let col = virt_off.col;
|
||||
let style = renderer.styles.severity_style(eol_diagnostic.severity());
|
||||
let width = renderer.renderer.viewport.width;
|
||||
let start_col = (col - renderer.renderer.offset.col) as u16;
|
||||
let mut end_col = start_col;
|
||||
let mut draw_col = (col + 1) as u16;
|
||||
|
||||
for line in eol_diagnostic.message.lines() {
|
||||
if !renderer.renderer.column_in_bounds(draw_col as usize, 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
(end_col, _) = renderer.renderer.set_string_truncated(
|
||||
renderer.renderer.viewport.x + draw_col,
|
||||
row,
|
||||
line,
|
||||
width.saturating_sub(draw_col) as usize,
|
||||
|_| style,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
|
||||
draw_col = end_col - renderer.renderer.viewport.x + 2; // double space between lines
|
||||
}
|
||||
|
||||
col_off = end_col - start_col;
|
||||
}
|
||||
|
||||
self.state.compute_line_diagnostics();
|
||||
|
|
Loading…
Add table
Reference in a new issue