Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/ui/document.rs')
-rw-r--r--helix-term/src/ui/document.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/helix-term/src/ui/document.rs b/helix-term/src/ui/document.rs
index 2da4d4b3..79145ba0 100644
--- a/helix-term/src/ui/document.rs
+++ b/helix-term/src/ui/document.rs
@@ -114,7 +114,7 @@ pub fn render_document(
}
#[allow(clippy::too_many_arguments)]
-pub fn render_text<'t>(
+pub fn render_text(
renderer: &mut TextRenderer,
text: RopeSlice<'_>,
anchor: usize,
@@ -348,6 +348,44 @@ impl<'a> TextRenderer<'a> {
offset,
}
}
+ /// Draws a single `grapheme` at the current render position with a specified `style`.
+ pub fn draw_decoration_grapheme(
+ &mut self,
+ grapheme: Grapheme,
+ mut style: Style,
+ mut row: u16,
+ col: u16,
+ ) -> bool {
+ if (row as usize) < self.offset.row
+ || row >= self.viewport.height
+ || col >= self.viewport.width
+ {
+ return false;
+ }
+ row -= self.offset.row as u16;
+ // TODO is it correct to apply the whitspace style to all unicode white spaces?
+ if grapheme.is_whitespace() {
+ style = style.patch(self.whitespace_style);
+ }
+
+ let grapheme = match grapheme {
+ Grapheme::Tab { width } => {
+ let grapheme_tab_width = char_to_byte_idx(&self.virtual_tab, width);
+ &self.virtual_tab[..grapheme_tab_width]
+ }
+ Grapheme::Other { ref g } if g == "\u{00A0}" => " ",
+ Grapheme::Other { ref g } => g,
+ Grapheme::Newline => " ",
+ };
+
+ self.surface.set_string(
+ self.viewport.x + col,
+ self.viewport.y + row,
+ grapheme,
+ style,
+ );
+ true
+ }
/// Draws a single `grapheme` at the current render position with a specified `style`.
pub fn draw_grapheme(