aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/editor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/ui/editor.rs')
-rw-r--r--helix-term/src/ui/editor.rs96
1 files changed, 38 insertions, 58 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 6b85d9a3..31195a4e 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -124,20 +124,16 @@ impl EditorView {
line_decorations.push(Box::new(line_decoration));
}
- let syntax_highlights =
+ let mut highlights =
Self::doc_syntax_highlights(doc, view.offset.anchor, inner.height, theme);
-
- let mut overlay_highlights =
- Self::empty_highlight_iter(doc, view.offset.anchor, inner.height);
- let overlay_syntax_highlights = Self::overlay_syntax_highlights(
+ let overlay_highlights = Self::overlay_syntax_highlights(
doc,
view.offset.anchor,
inner.height,
&text_annotations,
);
- if !overlay_syntax_highlights.is_empty() {
- overlay_highlights =
- Box::new(syntax::merge(overlay_highlights, overlay_syntax_highlights));
+ if !overlay_highlights.is_empty() {
+ highlights = Box::new(syntax::merge(highlights, overlay_highlights));
}
for diagnostic in Self::doc_diagnostics_highlights(doc, theme) {
@@ -146,12 +142,12 @@ impl EditorView {
if diagnostic.is_empty() {
continue;
}
- overlay_highlights = Box::new(syntax::merge(overlay_highlights, diagnostic));
+ highlights = Box::new(syntax::merge(highlights, diagnostic));
}
- if is_focused {
+ let highlights: Box<dyn Iterator<Item = HighlightEvent>> = if is_focused {
let highlights = syntax::merge(
- overlay_highlights,
+ highlights,
Self::doc_selection_highlights(
editor.mode(),
doc,
@@ -162,11 +158,13 @@ impl EditorView {
);
let focused_view_elements = Self::highlight_focused_view_elements(view, doc, theme);
if focused_view_elements.is_empty() {
- overlay_highlights = Box::new(highlights)
+ Box::new(highlights)
} else {
- overlay_highlights = Box::new(syntax::merge(highlights, focused_view_elements))
+ Box::new(syntax::merge(highlights, focused_view_elements))
}
- }
+ } else {
+ Box::new(highlights)
+ };
let gutter_overflow = view.gutter_offset(doc) == 0;
if !gutter_overflow {
@@ -199,8 +197,7 @@ impl EditorView {
doc,
view.offset,
&text_annotations,
- syntax_highlights,
- overlay_highlights,
+ highlights,
theme,
&mut line_decorations,
&mut translated_positions,
@@ -260,39 +257,27 @@ impl EditorView {
.for_each(|area| surface.set_style(area, ruler_theme))
}
- fn viewport_byte_range(
- text: helix_core::RopeSlice,
- row: usize,
- height: u16,
- ) -> std::ops::Range<usize> {
- // Calculate viewport byte ranges:
- // Saturating subs to make it inclusive zero indexing.
- let last_line = text.len_lines().saturating_sub(1);
- let last_visible_line = (row + height as usize).saturating_sub(1).min(last_line);
- let start = text.line_to_byte(row.min(last_line));
- let end = text.line_to_byte(last_visible_line + 1);
-
- start..end
- }
-
- pub fn empty_highlight_iter(
+ pub fn overlay_syntax_highlights(
doc: &Document,
anchor: usize,
height: u16,
- ) -> Box<dyn Iterator<Item = HighlightEvent>> {
+ text_annotations: &TextAnnotations,
+ ) -> Vec<(usize, std::ops::Range<usize>)> {
let text = doc.text().slice(..);
let row = text.char_to_line(anchor.min(text.len_chars()));
- // Calculate viewport byte ranges:
- // Saturating subs to make it inclusive zero indexing.
- let range = Self::viewport_byte_range(text, row, height);
- Box::new(
- [HighlightEvent::Source {
- start: text.byte_to_char(range.start),
- end: text.byte_to_char(range.end),
- }]
- .into_iter(),
- )
+ let range = {
+ // Calculate viewport byte ranges:
+ // Saturating subs to make it inclusive zero indexing.
+ let last_line = text.len_lines().saturating_sub(1);
+ let last_visible_line = (row + height as usize).saturating_sub(1).min(last_line);
+ let start = text.line_to_byte(row.min(last_line));
+ let end = text.line_to_byte(last_visible_line + 1);
+
+ start..end
+ };
+
+ text_annotations.collect_overlay_highlights(range)
}
/// Get syntax highlights for a document in a view represented by the first line
@@ -307,7 +292,16 @@ impl EditorView {
let text = doc.text().slice(..);
let row = text.char_to_line(anchor.min(text.len_chars()));
- let range = Self::viewport_byte_range(text, row, height);
+ let range = {
+ // Calculate viewport byte ranges:
+ // Saturating subs to make it inclusive zero indexing.
+ let last_line = text.len_lines().saturating_sub(1);
+ let last_visible_line = (row + height as usize).saturating_sub(1).min(last_line);
+ let start = text.line_to_byte(row.min(last_line));
+ let end = text.line_to_byte(last_visible_line + 1);
+
+ start..end
+ };
match doc.syntax() {
Some(syntax) => {
@@ -340,20 +334,6 @@ impl EditorView {
}
}
- pub fn overlay_syntax_highlights(
- doc: &Document,
- anchor: usize,
- height: u16,
- text_annotations: &TextAnnotations,
- ) -> Vec<(usize, std::ops::Range<usize>)> {
- let text = doc.text().slice(..);
- let row = text.char_to_line(anchor.min(text.len_chars()));
-
- let range = Self::viewport_byte_range(text, row, height);
-
- text_annotations.collect_overlay_highlights(range)
- }
-
/// Get highlight spans for document diagnostics
pub fn doc_diagnostics_highlights(
doc: &Document,