From b120515613ba24aff224d093b28d85049c774cad Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sat, 19 Sep 2020 11:55:42 +0900 Subject: Range based highlight_iter. Only works on limiting the start right now --- helix-term/src/editor.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'helix-term') diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs index ed2d3a13..e1288e07 100644 --- a/helix-term/src/editor.rs +++ b/helix-term/src/editor.rs @@ -104,13 +104,24 @@ impl Editor { state.doc().len_lines() - 1, ); + let range = { + // calculate viewport byte ranges + let start = state.doc().line_to_byte(self.first_line.into()); + let end = state.doc().line_to_byte(last_line) + + state.doc().line(last_line).len_bytes(); + + start..end + }; + + // TODO: range doesn't actually restrict source, just highlight range + // TODO: cache highlight results // TODO: only recalculate when state.doc is actually modified let highlights: Vec<_> = state .syntax .as_mut() .unwrap() - .highlight_iter(source_code.as_bytes(), None, |_| None) + .highlight_iter(source_code.as_bytes(), Some(range), None, |_| None) .unwrap() .collect(); // TODO: we collect here to avoid double borrow, fix later -- cgit v1.2.3-70-g09d2