on master help sign in
Prevent whitespace from rendering inside inlay hints (#6312)

* fix spaces and nbsps showing in inlay hints * remove origin * virtual tab + fix unneeded clone * update virtual tab determining location * fix clippy lint

commit2a27d1b505a676c436a4b4d37d7124f9bc098225 authorThomas Schollenberger <iamzenthial@gmail.com> dateThu 16 Mar 2023, 02:45 (4 years ago) parentaae8f72
1 file changed+17−4
helix-term/src/ui/document.rs+17−4
helix-term/src/ui/document.rs+17−4
@@ -287,9 +287,11 @@ pub fn render_text<'t>(
287287 style_span.0
288288 };
289289
290+ let virt = grapheme.is_virtual();
290291 renderer.draw_grapheme(
291292 grapheme.grapheme,
292293 grapheme_style,
294+ virt,
293295 &mut last_line_indent_level,
294296 &mut is_in_indent_area,
295297 pos,
@@ -313,6 +315,7 @@ pub struct TextRenderer<'a> {
313315 pub nbsp: String,
314316 pub space: String,
315317 pub tab: String,
318+ pub virtual_tab: String,
316319 pub indent_width: u16,
317320 pub starting_indent: usize,
318321 pub draw_indent_guides: bool,
@@ -342,6 +345,7 @@ impl<'a> TextRenderer<'a> {
342345 } else {
343346 " ".repeat(tab_width)
344347 };
348+ let virtual_tab = " ".repeat(tab_width);
345349 let newline = if ws_render.newline() == WhitespaceRenderValue::All {
346350 ws_chars.newline.into()
347351 } else {
@@ -370,6 +374,7 @@ impl<'a> TextRenderer<'a> {
370374 nbsp,
371375 space,
372376 tab,
377+ virtual_tab,
373378 whitespace_style: theme.get("ui.virtual.whitespace"),
374379 indent_width,
375380 starting_indent: col_offset / indent_width as usize
@@ -392,6 +397,7 @@ impl<'a> TextRenderer<'a> {
392397 &mut self,
393398 grapheme: Grapheme,
394399 mut style: Style,
400+ is_virtual: bool,
395401 last_indent_level: &mut usize,
396402 is_in_indent_area: &mut bool,
397403 position: Position,
@@ -405,14 +411,21 @@ impl<'a> TextRenderer<'a> {
405411 }
406412
407413 let width = grapheme.width();
414+ let space = if is_virtual { " " } else { &self.space };
415+ let nbsp = if is_virtual { " " } else { &self.nbsp };
416+ let tab = if is_virtual {
417+ &self.virtual_tab
418+ } else {
419+ &self.tab
420+ };
408421 let grapheme = match grapheme {
409422 Grapheme::Tab { width } => {
410− let grapheme_tab_width = char_to_byte_idx(&self.tab, width);
411− &self.tab[..grapheme_tab_width]
423+ let grapheme_tab_width = char_to_byte_idx(tab, width);
424+ &tab[..grapheme_tab_width]
412425 }
413426 // TODO special rendering for other whitespaces?
414− Grapheme::Other { ref g } if g == " " => &self.space,
415− Grapheme::Other { ref g } if g == "\u{00A0}" => &self.nbsp,
427+ Grapheme::Other { ref g } if g == " " => space,
428+ Grapheme::Other { ref g } if g == "\u{00A0}" => nbsp,
416429 Grapheme::Other { ref g } => g,
417430 Grapheme::Newline => &self.newline,
418431 };