diff options
author | Blaž Hrastnik | 2022-01-26 02:58:52 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-01-30 13:38:44 +0000 |
commit | 62561e9d230c0a62e46c522b24befb7113117e00 (patch) | |
tree | 854f72abc6b0f74b342d8a70d337fa7db424b12d | |
parent | 5aead46f4b4ce876701eb5aa2c2a44e286088977 (diff) |
Stop collecting highlight_iter events then turning back into iter
-rw-r--r-- | helix-term/src/ui/editor.rs | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index cfc32f4f..d3af921e 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -139,31 +139,34 @@ impl EditorView { start..end }; - // TODO: range doesn't actually restrict source, just highlight range - let highlights = match doc.syntax() { + match doc.syntax() { Some(syntax) => { - syntax + let iter = syntax + // TODO: range doesn't actually restrict source, just highlight range .highlight_iter(text.slice(..), Some(range), None) .map(|event| event.unwrap()) - .collect() // TODO: we collect here to avoid holding the lock, fix later + .map(move |event| match event { + // convert byte offsets to char offset + HighlightEvent::Source { start, end } => { + let start = + text.byte_to_char(ensure_grapheme_boundary_next_byte(text, start)); + let end = + text.byte_to_char(ensure_grapheme_boundary_next_byte(text, end)); + HighlightEvent::Source { start, end } + } + event => event, + }); + + Box::new(iter) } - None => vec![HighlightEvent::Source { - start: range.start, - end: range.end, - }], + None => Box::new( + [HighlightEvent::Source { + start: text.byte_to_char(range.start), + end: text.byte_to_char(range.end), + }] + .into_iter(), + ), } - .into_iter() - .map(move |event| match event { - // convert byte offsets to char offset - HighlightEvent::Source { start, end } => { - let start = text.byte_to_char(ensure_grapheme_boundary_next_byte(text, start)); - let end = text.byte_to_char(ensure_grapheme_boundary_next_byte(text, end)); - HighlightEvent::Source { start, end } - } - event => event, - }); - - Box::new(highlights) } /// Get highlight spans for document diagnostics |