From 1068e0beef101baf2738768ed34e02d9a00511a1 Mon Sep 17 00:00:00 2001 From: SoraTenshi Date: Thu, 6 Apr 2023 16:07:06 +0000 Subject: [PATCH] Remove all virtual text when drawing sticky nodes --- helix-core/src/text_annotations.rs | 6 ++++++ helix-term/src/ui/editor.rs | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/helix-core/src/text_annotations.rs b/helix-core/src/text_annotations.rs index 3e48de4d8..1ba03e4e9 100644 --- a/helix-core/src/text_annotations.rs +++ b/helix-core/src/text_annotations.rs @@ -234,6 +234,12 @@ impl TextAnnotations { self.line_annotations.clear(); } + /// Removes all inline annotations, useful if you don't want to draw + /// any virtual text. + pub fn clear_inline_annotations(&mut self) { + self.inline_annotations.clear(); + } + pub(crate) fn next_inline_annotation_at( &self, char_idx: usize, diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index ac49aa620..4c026bae1 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -824,13 +824,17 @@ impl EditorView { // get the len of bytes of the text that will be written (the "definition" line) let line = text.line(node.line); - let tab_width_count = line.chars().filter(|c| *c == '\t').count(); + let tab_count = line.chars().filter(|c| *c == '\t').count(); let already_written = - (line.len_bytes() + tab_width_count.saturating_mul(doc.tab_width() - 1)) as u16; + (line.len_bytes() + tab_count.saturating_mul(doc.tab_width() - 1)) as u16; let dots = "..."; + let mut cleared_virtual_text_annotations = doc_annotations.clone(); + cleared_virtual_text_annotations.clear_line_annotations(); + cleared_virtual_text_annotations.clear_inline_annotations(); + // if the definition of the function contains multiple lines if node.has_context_end { let last_line = text.byte_to_line(node.byte_range.end); @@ -857,12 +861,13 @@ impl EditorView { ); new_offset.anchor = text.byte_to_char(node.byte_range.end); let highlights = Self::doc_syntax_highlights(doc, new_offset.anchor, 1, theme); + render_text( &mut renderer, text, new_offset, &doc.text_format(additional_area.width, Some(theme)), - doc_annotations, + &cleared_virtual_text_annotations, highlights, theme, line_decoration, @@ -900,7 +905,7 @@ impl EditorView { text, new_offset, &doc.text_format(line_context_area.width, Some(theme)), - doc_annotations, + &cleared_virtual_text_annotations, highlights, theme, line_decoration,