From 9a8bea105f1e030b49fd36806c71471c55f26804 Mon Sep 17 00:00:00 2001 From: tomKPZ Date: Wed, 20 Apr 2022 20:26:43 -0700 Subject: [PATCH 01/10] Visible whitespace only for selections --- book/src/configuration.md | 2 +- helix-core/src/syntax.rs | 17 +++++++++ helix-term/src/ui/editor.rs | 67 +++++++++++++++++++++++++---------- helix-term/src/ui/markdown.rs | 4 ++- helix-view/src/editor.rs | 3 +- 5 files changed, 70 insertions(+), 23 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index e418869fc223..5ea1e430baa4 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -189,7 +189,7 @@ Options for rendering whitespace with visible characters. Use `:set whitespace.r | Key | Description | Default | |-----|-------------|---------| -| `render` | Whether to render whitespace. May either be `"all"` or `"none"`, or a table with sub-keys `space`, `tab`, and `newline`. | `"none"` | +| `render` | Whether to render whitespace. May either be `"all"`, `"selection"`, or `"none"`, or a table with sub-keys `space`, `tab`, and `newline`. | `"none"` | | `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp` or `newline` | See example below | Example diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 99922d3774c1..24bf45aa1fc4 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -1144,6 +1144,8 @@ pub enum HighlightEvent { Source { start: usize, end: usize }, HighlightStart(Highlight), HighlightEnd, + SelectionStart, + SelectionEnd, } /// Contains the data needed to highlight code written in a particular language. @@ -1859,6 +1861,7 @@ fn injection_for_match<'a>( pub struct Merge { iter: I, spans: Box)>>, + events: Option<(HighlightEvent, HighlightEvent)>, next_event: Option, next_span: Option<(usize, std::ops::Range)>, @@ -1870,11 +1873,13 @@ pub struct Merge { pub fn merge>( iter: I, spans: Vec<(usize, std::ops::Range)>, + events: Option<(HighlightEvent, HighlightEvent)>, ) -> Merge { let spans = Box::new(spans.into_iter()); let mut merge = Merge { iter, spans, + events, next_event: None, next_span: None, queue: Vec::new(), @@ -1940,11 +1945,17 @@ impl> Iterator for Merge { let event = HighlightStart(Highlight(*span)); // enqueue in reverse order + if let Some((_, end)) = self.events { + self.queue.push(end) + } self.queue.push(HighlightEnd); self.queue.push(Source { start, end: intersect, }); + if let Some((start, _)) = self.events { + self.queue.push(start) + } if end == intersect { // the event is complete @@ -1976,11 +1987,17 @@ impl> Iterator for Merge { // all `Source` events point to valid indices in the rope. (None, Some((span, range))) => { let event = HighlightStart(Highlight(*span)); + if let Some((_, end)) = self.events { + self.queue.push(end) + } self.queue.push(HighlightEnd); self.queue.push(Source { start: range.start, end: range.end, }); + if let Some((start, _)) = self.events { + self.queue.push(start) + } self.next_span = self.spans.next(); Some(event) } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 6b3163748fa2..254efa96ad0b 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -119,11 +119,16 @@ impl EditorView { } let highlights = Self::doc_syntax_highlights(doc, view.offset, inner.height, theme); - let highlights = syntax::merge(highlights, Self::doc_diagnostics_highlights(doc, theme)); + let highlights = syntax::merge( + highlights, + Self::doc_diagnostics_highlights(doc, theme), + None, + ); let highlights: Box> = if is_focused { Box::new(syntax::merge( highlights, Self::doc_selection_highlights(doc, view, theme, &editor.config().cursor_shape), + Some((HighlightEvent::SelectionStart, HighlightEvent::SelectionEnd)), )) } else { Box::new(highlights) @@ -395,18 +400,33 @@ impl EditorView { let mut visual_x = 0u16; let mut line = 0u16; let tab_width = doc.tab_width(); - let tab = if whitespace.render.tab() == WhitespaceRenderValue::All { - (1..tab_width).fold(whitespace.characters.tab.to_string(), |s, _| s + " ") - } else { - " ".repeat(tab_width) - }; - let space = whitespace.characters.space.to_string(); - let nbsp = whitespace.characters.nbsp.to_string(); - let newline = if whitespace.render.newline() == WhitespaceRenderValue::All { - whitespace.characters.newline.to_string() - } else { - " ".to_string() - }; + let tab_hidden = " ".repeat(tab_width); + let tab_visible = + (1..tab_width).fold(whitespace.characters.tab.to_string(), |s, _| s + " "); + let space_visible = whitespace.characters.space.to_string(); + let nbsp_visible = whitespace.characters.nbsp.to_string(); + let newline_visible = whitespace.characters.newline.to_string(); + fn render_whitespace<'a>( + hidden: &'a str, + visible: &'a str, + pref: WhitespaceRenderValue, + ) -> Box &'a str + 'a> { + Box::new(move |selected| match pref { + WhitespaceRenderValue::None => hidden, + WhitespaceRenderValue::All => visible, + WhitespaceRenderValue::Selection => { + if selected { + visible + } else { + hidden + } + } + }) + } + let tab = render_whitespace(&tab_hidden, &tab_visible, whitespace.render.tab()); + let space = render_whitespace(" ", &space_visible, whitespace.render.space()); + let nbsp = render_whitespace(" ",  _visible, whitespace.render.nbsp()); + let newline = render_whitespace(" ", &newline_visible, whitespace.render.newline()); let indent_guide_char = config.indent_guides.character.to_string(); let text_style = theme.get("ui.text"); @@ -441,6 +461,8 @@ impl EditorView { } }; + let mut selected = false; + 'outer: for event in highlights { match event { HighlightEvent::HighlightStart(span) => { @@ -449,6 +471,12 @@ impl EditorView { HighlightEvent::HighlightEnd => { spans.pop(); } + HighlightEvent::SelectionStart => { + selected = true; + } + HighlightEvent::SelectionEnd => { + selected = false; + } HighlightEvent::Source { start, end } => { let is_trailing_cursor = text.len_chars() < end; @@ -460,18 +488,18 @@ impl EditorView { .iter() .fold(text_style, |acc, span| acc.patch(theme.highlight(span.0))); - let space = if whitespace.render.space() == WhitespaceRenderValue::All + let space = if whitespace.render.space() != WhitespaceRenderValue::None && !is_trailing_cursor { - &space + space(selected) } else { " " }; - let nbsp = if whitespace.render.nbsp() == WhitespaceRenderValue::All + let nbsp = if whitespace.render.nbsp() != WhitespaceRenderValue::None && text.len_chars() < end { -   + nbsp(selected) } else { " " }; @@ -488,7 +516,7 @@ impl EditorView { surface.set_string( viewport.x + visual_x - offset.col as u16, viewport.y + line, - &newline, + newline(selected), style.patch(whitespace_style), ); } @@ -511,8 +539,9 @@ impl EditorView { is_whitespace = true; // make sure we display tab as appropriate amount of spaces let visual_tab_width = tab_width - (visual_x as usize % tab_width); + let tab = tab(selected); let grapheme_tab_width = - helix_core::str_utils::char_to_byte_idx(&tab, visual_tab_width); + helix_core::str_utils::char_to_byte_idx(tab, visual_tab_width); (&tab[..grapheme_tab_width], visual_tab_width) } else if grapheme == " " { diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index c53b3b6692fb..db972a0316d3 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -61,7 +61,7 @@ pub fn highlighted_code_block<'a>( .map(|e| e.unwrap()); let highlight_iter: Box> = if let Some(spans) = additional_highlight_spans { - Box::new(helix_core::syntax::merge(highlight_iter, spans)) + Box::new(helix_core::syntax::merge(highlight_iter, spans, None)) } else { Box::new(highlight_iter) }; @@ -75,6 +75,8 @@ pub fn highlighted_code_block<'a>( HighlightEvent::HighlightEnd => { highlights.pop(); } + HighlightEvent::SelectionStart => {} + HighlightEvent::SelectionEnd => {} HighlightEvent::Source { start, end } => { let style = highlights .iter() diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 1e7f508c14bf..e831ec65071e 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -392,8 +392,7 @@ pub enum WhitespaceRender { #[serde(rename_all = "kebab-case")] pub enum WhitespaceRenderValue { None, - // TODO - // Selection, + Selection, All, } From 45d79fb35385eb60de5a96e96ab99fe738a0fcb2 Mon Sep 17 00:00:00 2001 From: tomKPZ Date: Mon, 8 Aug 2022 17:12:51 -0700 Subject: [PATCH 02/10] only emit selection events when necessary --- helix-term/src/ui/editor.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 254efa96ad0b..4a88897ce5ca 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -118,6 +118,18 @@ impl EditorView { Self::highlight_cursorline(doc, view, surface, theme); } + let whitespace = &editor.config().whitespace; + use helix_view::editor::WhitespaceRenderValue; + let whitespace_events = if whitespace.render.tab() == WhitespaceRenderValue::Selection + || whitespace.render.nbsp() == WhitespaceRenderValue::Selection + || whitespace.render.space() == WhitespaceRenderValue::Selection + || whitespace.render.newline() == WhitespaceRenderValue::Selection + { + Some((HighlightEvent::SelectionStart, HighlightEvent::SelectionEnd)) + } else { + None + }; + let highlights = Self::doc_syntax_highlights(doc, view.offset, inner.height, theme); let highlights = syntax::merge( highlights, @@ -128,7 +140,7 @@ impl EditorView { Box::new(syntax::merge( highlights, Self::doc_selection_highlights(doc, view, theme, &editor.config().cursor_shape), - Some((HighlightEvent::SelectionStart, HighlightEvent::SelectionEnd)), + whitespace_events, )) } else { Box::new(highlights) From 3063bd390599e7f0ee835702ea498a4402d1d531 Mon Sep 17 00:00:00 2001 From: tomKPZ Date: Wed, 10 Aug 2022 12:53:21 -0700 Subject: [PATCH 03/10] Remove selection events --- helix-core/src/syntax.rs | 53 ++++++++++++++++++----------------- helix-term/src/ui/editor.rs | 38 ++++++++----------------- helix-term/src/ui/markdown.rs | 8 ++---- 3 files changed, 43 insertions(+), 56 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 24bf45aa1fc4..5dadcd03e065 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -1141,11 +1141,15 @@ pub enum Error { /// Represents a single step in rendering a syntax-highlighted document. #[derive(Copy, Clone, Debug)] pub enum HighlightEvent { - Source { start: usize, end: usize }, - HighlightStart(Highlight), + Source { + start: usize, + end: usize, + }, + HighlightStart { + highlight: Highlight, + is_selection: bool, + }, HighlightEnd, - SelectionStart, - SelectionEnd, } /// Contains the data needed to highlight code written in a particular language. @@ -1799,8 +1803,13 @@ impl<'a> Iterator for HighlightIter<'a> { if let Some(highlight) = reference_highlight.or(current_highlight) { self.last_highlight_range = Some((range.start, range.end, layer.depth)); layer.highlight_end_stack.push(range.end); - return self - .emit_event(range.start, Some(HighlightEvent::HighlightStart(highlight))); + return self.emit_event( + range.start, + Some(HighlightEvent::HighlightStart { + highlight, + is_selection: false, + }), + ); } self.sort_layers(); @@ -1861,7 +1870,7 @@ fn injection_for_match<'a>( pub struct Merge { iter: I, spans: Box)>>, - events: Option<(HighlightEvent, HighlightEvent)>, + is_selection: bool, next_event: Option, next_span: Option<(usize, std::ops::Range)>, @@ -1873,13 +1882,13 @@ pub struct Merge { pub fn merge>( iter: I, spans: Vec<(usize, std::ops::Range)>, - events: Option<(HighlightEvent, HighlightEvent)>, + is_selection: bool, ) -> Merge { let spans = Box::new(spans.into_iter()); let mut merge = Merge { iter, spans, - events, + is_selection, next_event: None, next_span: None, queue: Vec::new(), @@ -1912,9 +1921,9 @@ impl> Iterator for Merge { } match (self.next_event, &self.next_span) { - (Some(HighlightStart(i)), _) => { + (highlight_start @ Some(HighlightStart { .. }), _) => { self.next_event = self.iter.next(); - Some(HighlightStart(i)) + highlight_start } (Some(HighlightEnd), _) => { self.next_event = self.iter.next(); @@ -1942,20 +1951,17 @@ impl> Iterator for Merge { } (Some(Source { start, end }), Some((span, range))) if start == range.start => { let intersect = range.end.min(end); - let event = HighlightStart(Highlight(*span)); + let event = HighlightStart { + highlight: Highlight(*span), + is_selection: self.is_selection, + }; // enqueue in reverse order - if let Some((_, end)) = self.events { - self.queue.push(end) - } self.queue.push(HighlightEnd); self.queue.push(Source { start, end: intersect, }); - if let Some((start, _)) = self.events { - self.queue.push(start) - } if end == intersect { // the event is complete @@ -1986,18 +1992,15 @@ impl> Iterator for Merge { // handled appropriately by the drawing code by not assuming that // all `Source` events point to valid indices in the rope. (None, Some((span, range))) => { - let event = HighlightStart(Highlight(*span)); - if let Some((_, end)) = self.events { - self.queue.push(end) - } + let event = HighlightStart { + highlight: Highlight(*span), + is_selection: self.is_selection, + }; self.queue.push(HighlightEnd); self.queue.push(Source { start: range.start, end: range.end, }); - if let Some((start, _)) = self.events { - self.queue.push(start) - } self.next_span = self.spans.next(); Some(event) } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 4a88897ce5ca..383248ff1a6f 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -118,29 +118,17 @@ impl EditorView { Self::highlight_cursorline(doc, view, surface, theme); } - let whitespace = &editor.config().whitespace; - use helix_view::editor::WhitespaceRenderValue; - let whitespace_events = if whitespace.render.tab() == WhitespaceRenderValue::Selection - || whitespace.render.nbsp() == WhitespaceRenderValue::Selection - || whitespace.render.space() == WhitespaceRenderValue::Selection - || whitespace.render.newline() == WhitespaceRenderValue::Selection - { - Some((HighlightEvent::SelectionStart, HighlightEvent::SelectionEnd)) - } else { - None - }; - let highlights = Self::doc_syntax_highlights(doc, view.offset, inner.height, theme); let highlights = syntax::merge( highlights, Self::doc_diagnostics_highlights(doc, theme), - None, + false, ); let highlights: Box> = if is_focused { Box::new(syntax::merge( highlights, Self::doc_selection_highlights(doc, view, theme, &editor.config().cursor_shape), - whitespace_events, + true, )) } else { Box::new(highlights) @@ -477,17 +465,15 @@ impl EditorView { 'outer: for event in highlights { match event { - HighlightEvent::HighlightStart(span) => { - spans.push(span); + HighlightEvent::HighlightStart { + highlight, + is_selection, + } => { + spans.push((highlight, is_selection)); + selected |= is_selection; } HighlightEvent::HighlightEnd => { - spans.pop(); - } - HighlightEvent::SelectionStart => { - selected = true; - } - HighlightEvent::SelectionEnd => { - selected = false; + selected &= !spans.pop().unwrap().1; } HighlightEvent::Source { start, end } => { let is_trailing_cursor = text.len_chars() < end; @@ -496,9 +482,9 @@ impl EditorView { // the rope, to allow cursor highlighting at the end // of the rope. let text = text.get_slice(start..end).unwrap_or_else(|| " ".into()); - let style = spans - .iter() - .fold(text_style, |acc, span| acc.patch(theme.highlight(span.0))); + let style = spans.iter().fold(text_style, |acc, span| { + acc.patch(theme.highlight(span.0 .0)) + }); let space = if whitespace.render.space() != WhitespaceRenderValue::None && !is_trailing_cursor diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index db972a0316d3..9cde0db0e9e5 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -61,7 +61,7 @@ pub fn highlighted_code_block<'a>( .map(|e| e.unwrap()); let highlight_iter: Box> = if let Some(spans) = additional_highlight_spans { - Box::new(helix_core::syntax::merge(highlight_iter, spans, None)) + Box::new(helix_core::syntax::merge(highlight_iter, spans, false)) } else { Box::new(highlight_iter) }; @@ -69,14 +69,12 @@ pub fn highlighted_code_block<'a>( let mut highlights = Vec::new(); for event in highlight_iter { match event { - HighlightEvent::HighlightStart(span) => { - highlights.push(span); + HighlightEvent::HighlightStart{highlight, is_selection: _} => { + highlights.push(highlight); } HighlightEvent::HighlightEnd => { highlights.pop(); } - HighlightEvent::SelectionStart => {} - HighlightEvent::SelectionEnd => {} HighlightEvent::Source { start, end } => { let style = highlights .iter() From c83ee603c42cd4ee8248e98c925ecc1cdc36feb2 Mon Sep 17 00:00:00 2001 From: tomKPZ Date: Wed, 10 Aug 2022 15:58:07 -0700 Subject: [PATCH 04/10] Code review 2 --- helix-core/src/syntax.rs | 36 ++++++++--------------------------- helix-term/src/ui/editor.rs | 35 ++++++++++++++-------------------- helix-term/src/ui/markdown.rs | 6 +++--- helix-view/src/theme.rs | 12 ++++++++++++ 4 files changed, 37 insertions(+), 52 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 5dadcd03e065..99922d3774c1 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -1141,14 +1141,8 @@ pub enum Error { /// Represents a single step in rendering a syntax-highlighted document. #[derive(Copy, Clone, Debug)] pub enum HighlightEvent { - Source { - start: usize, - end: usize, - }, - HighlightStart { - highlight: Highlight, - is_selection: bool, - }, + Source { start: usize, end: usize }, + HighlightStart(Highlight), HighlightEnd, } @@ -1803,13 +1797,8 @@ impl<'a> Iterator for HighlightIter<'a> { if let Some(highlight) = reference_highlight.or(current_highlight) { self.last_highlight_range = Some((range.start, range.end, layer.depth)); layer.highlight_end_stack.push(range.end); - return self.emit_event( - range.start, - Some(HighlightEvent::HighlightStart { - highlight, - is_selection: false, - }), - ); + return self + .emit_event(range.start, Some(HighlightEvent::HighlightStart(highlight))); } self.sort_layers(); @@ -1870,7 +1859,6 @@ fn injection_for_match<'a>( pub struct Merge { iter: I, spans: Box)>>, - is_selection: bool, next_event: Option, next_span: Option<(usize, std::ops::Range)>, @@ -1882,13 +1870,11 @@ pub struct Merge { pub fn merge>( iter: I, spans: Vec<(usize, std::ops::Range)>, - is_selection: bool, ) -> Merge { let spans = Box::new(spans.into_iter()); let mut merge = Merge { iter, spans, - is_selection, next_event: None, next_span: None, queue: Vec::new(), @@ -1921,9 +1907,9 @@ impl> Iterator for Merge { } match (self.next_event, &self.next_span) { - (highlight_start @ Some(HighlightStart { .. }), _) => { + (Some(HighlightStart(i)), _) => { self.next_event = self.iter.next(); - highlight_start + Some(HighlightStart(i)) } (Some(HighlightEnd), _) => { self.next_event = self.iter.next(); @@ -1951,10 +1937,7 @@ impl> Iterator for Merge { } (Some(Source { start, end }), Some((span, range))) if start == range.start => { let intersect = range.end.min(end); - let event = HighlightStart { - highlight: Highlight(*span), - is_selection: self.is_selection, - }; + let event = HighlightStart(Highlight(*span)); // enqueue in reverse order self.queue.push(HighlightEnd); @@ -1992,10 +1975,7 @@ impl> Iterator for Merge { // handled appropriately by the drawing code by not assuming that // all `Source` events point to valid indices in the rope. (None, Some((span, range))) => { - let event = HighlightStart { - highlight: Highlight(*span), - is_selection: self.is_selection, - }; + let event = HighlightStart(Highlight(*span)); self.queue.push(HighlightEnd); self.queue.push(Source { start: range.start, diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 383248ff1a6f..b6c5fd5ee4de 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -119,16 +119,11 @@ impl EditorView { } let highlights = Self::doc_syntax_highlights(doc, view.offset, inner.height, theme); - let highlights = syntax::merge( - highlights, - Self::doc_diagnostics_highlights(doc, theme), - false, - ); + let highlights = syntax::merge(highlights, Self::doc_diagnostics_highlights(doc, theme)); let highlights: Box> = if is_focused { Box::new(syntax::merge( highlights, Self::doc_selection_highlights(doc, view, theme, &editor.config().cursor_shape), - true, )) } else { Box::new(highlights) @@ -461,19 +456,17 @@ impl EditorView { } }; - let mut selected = false; + let mut selecting = false; 'outer: for event in highlights { match event { - HighlightEvent::HighlightStart { - highlight, - is_selection, - } => { - spans.push((highlight, is_selection)); - selected |= is_selection; + HighlightEvent::HighlightStart(span) => { + spans.push(span); + selecting |= theme.selection_scopes().contains(&span.0); } HighlightEvent::HighlightEnd => { - selected &= !spans.pop().unwrap().1; + let span = spans.pop().unwrap(); + selecting &= !theme.selection_scopes().contains(&span.0); } HighlightEvent::Source { start, end } => { let is_trailing_cursor = text.len_chars() < end; @@ -482,14 +475,14 @@ impl EditorView { // the rope, to allow cursor highlighting at the end // of the rope. let text = text.get_slice(start..end).unwrap_or_else(|| " ".into()); - let style = spans.iter().fold(text_style, |acc, span| { - acc.patch(theme.highlight(span.0 .0)) - }); + let style = spans + .iter() + .fold(text_style, |acc, span| acc.patch(theme.highlight(span.0))); let space = if whitespace.render.space() != WhitespaceRenderValue::None && !is_trailing_cursor { - space(selected) + space(selecting) } else { " " }; @@ -497,7 +490,7 @@ impl EditorView { let nbsp = if whitespace.render.nbsp() != WhitespaceRenderValue::None && text.len_chars() < end { - nbsp(selected) + nbsp(selecting) } else { " " }; @@ -514,7 +507,7 @@ impl EditorView { surface.set_string( viewport.x + visual_x - offset.col as u16, viewport.y + line, - newline(selected), + newline(selecting), style.patch(whitespace_style), ); } @@ -537,7 +530,7 @@ impl EditorView { is_whitespace = true; // make sure we display tab as appropriate amount of spaces let visual_tab_width = tab_width - (visual_x as usize % tab_width); - let tab = tab(selected); + let tab = tab(selecting); let grapheme_tab_width = helix_core::str_utils::char_to_byte_idx(tab, visual_tab_width); diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index 9cde0db0e9e5..c53b3b6692fb 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -61,7 +61,7 @@ pub fn highlighted_code_block<'a>( .map(|e| e.unwrap()); let highlight_iter: Box> = if let Some(spans) = additional_highlight_spans { - Box::new(helix_core::syntax::merge(highlight_iter, spans, false)) + Box::new(helix_core::syntax::merge(highlight_iter, spans)) } else { Box::new(highlight_iter) }; @@ -69,8 +69,8 @@ pub fn highlighted_code_block<'a>( let mut highlights = Vec::new(); for event in highlight_iter { match event { - HighlightEvent::HighlightStart{highlight, is_selection: _} => { - highlights.push(highlight); + HighlightEvent::HighlightStart(span) => { + highlights.push(span); } HighlightEvent::HighlightEnd => { highlights.pop(); diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index fa5fa702804b..a1c2b0234339 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -1,5 +1,6 @@ use std::{ collections::HashMap, + collections::HashSet, path::{Path, PathBuf}, }; @@ -102,6 +103,7 @@ pub struct Theme { styles: HashMap, // tree-sitter highlight styles are stored in a Vec to optimize lookups scopes: Vec, + selection_scopes: HashSet, highlights: Vec