Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/ui/editor.rs')
-rw-r--r--helix-term/src/ui/editor.rs77
1 files changed, 23 insertions, 54 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index b25af107..6fca4b1b 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -14,7 +14,6 @@ use crate::{
};
use helix_core::{
- diagnostic::NumberOrString,
graphemes::{next_grapheme_boundary, prev_grapheme_boundary},
movement::Direction,
syntax::{self, OverlayHighlights},
@@ -127,18 +126,6 @@ impl EditorView {
&text_annotations,
));
- if doc
- .language_config()
- .and_then(|config| config.rainbow_brackets)
- .unwrap_or(config.rainbow_brackets)
- {
- if let Some(overlay) =
- Self::doc_rainbow_highlights(doc, view_offset.anchor, inner.height, theme, &loader)
- {
- overlays.push(overlay);
- }
- }
-
Self::doc_diagnostics_highlights_into(doc, theme, &mut overlays);
if is_focused {
@@ -316,34 +303,15 @@ impl EditorView {
text_annotations.collect_overlay_highlights(range)
}
- pub fn doc_rainbow_highlights(
- doc: &Document,
- anchor: usize,
- height: u16,
- theme: &Theme,
- loader: &syntax::Loader,
- ) -> Option<OverlayHighlights> {
- let syntax = doc.syntax()?;
- let text = doc.text().slice(..);
- let row = text.char_to_line(anchor.min(text.len_chars()));
- let visible_range = Self::viewport_byte_range(text, row, height);
- let start = syntax::child_for_byte_range(
- &syntax.tree().root_node(),
- visible_range.start as u32..visible_range.end as u32,
- )
- .map_or(visible_range.start as u32, |node| node.start_byte());
- let range = start..visible_range.end as u32;
-
- Some(syntax.rainbow_highlights(text, theme.rainbow_length(), loader, range))
- }
-
/// Get highlight spans for document diagnostics
pub fn doc_diagnostics_highlights_into(
doc: &Document,
theme: &Theme,
overlay_highlights: &mut Vec<OverlayHighlights>,
) {
- use helix_core::diagnostic::{DiagnosticTag, Range, Severity};
+ use helix_core::diagnostic::Severity;
+ use helix_stdx::Range;
+ use helix_view::diagnostic::DiagnosticTag;
let get_scope_of = |scope| {
theme
.find_highlight_exact(scope)
@@ -386,7 +354,7 @@ impl EditorView {
for diagnostic in doc.diagnostics() {
// Separate diagnostics into different Vecs by severity.
- let vec = match diagnostic.severity {
+ let vec = match diagnostic.inner.severity {
Some(Severity::Info) => &mut info_vec,
Some(Severity::Hint) => &mut hint_vec,
Some(Severity::Warning) => &mut warning_vec,
@@ -398,16 +366,16 @@ impl EditorView {
// the diagnostic as info/hint/default and only render it as unnecessary/deprecated
// instead. For warning/error diagnostics, render both the severity highlight and
// the tag highlight.
- if diagnostic.tags.is_empty()
+ if diagnostic.inner.tags.is_empty()
|| matches!(
- diagnostic.severity,
+ diagnostic.inner.severity,
Some(Severity::Warning | Severity::Error)
)
{
push_diagnostic(vec, diagnostic.range);
}
- for tag in &diagnostic.tags {
+ for tag in &diagnostic.inner.tags {
match tag {
DiagnosticTag::Unnecessary => {
if unnecessary.is_some() {
@@ -538,7 +506,7 @@ impl EditorView {
};
spans.push((selection_scope, range.anchor..selection_end));
// add block cursors
- // skip primary cursor if terminal is unfocused - terminal cursor is used in that case
+ // skip primary cursor if terminal is unfocused - crossterm cursor is used in that case
if !selection_is_primary || (cursor_is_block && is_terminal_focused) {
spans.push((cursor_scope, cursor_start..range.head));
}
@@ -546,7 +514,7 @@ impl EditorView {
// Reverse case.
let cursor_end = next_grapheme_boundary(text, range.head);
// add block cursors
- // skip primary cursor if terminal is unfocused - terminal cursor is used in that case
+ // skip primary cursor if terminal is unfocused - crossterm cursor is used in that case
if !selection_is_primary || (cursor_is_block && is_terminal_focused) {
spans.push((cursor_scope, range.head..cursor_end));
}
@@ -717,6 +685,7 @@ impl EditorView {
theme: &Theme,
) {
use helix_core::diagnostic::Severity;
+ use helix_view::diagnostic::NumberOrString;
use tui::{
layout::Alignment,
text::Text,
@@ -740,17 +709,18 @@ impl EditorView {
let mut lines = Vec::new();
let background_style = theme.get("ui.background");
for diagnostic in diagnostics {
- let style = Style::reset()
- .patch(background_style)
- .patch(match diagnostic.severity {
- Some(Severity::Error) => error,
- Some(Severity::Warning) | None => warning,
- Some(Severity::Info) => info,
- Some(Severity::Hint) => hint,
- });
- let text = Text::styled(&diagnostic.message, style);
+ let style =
+ Style::reset()
+ .patch(background_style)
+ .patch(match diagnostic.inner.severity {
+ Some(Severity::Error) => error,
+ Some(Severity::Warning) | None => warning,
+ Some(Severity::Info) => info,
+ Some(Severity::Hint) => hint,
+ });
+ let text = Text::styled(&diagnostic.inner.message, style);
lines.extend(text.lines);
- let code = diagnostic.code.as_ref().map(|x| match x {
+ let code = diagnostic.inner.code.as_ref().map(|x| match x {
NumberOrString::Number(n) => format!("({n})"),
NumberOrString::String(s) => format!("({s})"),
});
@@ -1159,8 +1129,6 @@ impl EditorView {
let editor = &mut cxt.editor;
if let Some((pos, view_id)) = pos_and_view(editor, row, column, true) {
- editor.focus(view_id);
-
let prev_view_id = view!(editor).id;
let doc = doc_mut!(editor, &view!(editor, view_id).doc);
@@ -1184,6 +1152,7 @@ impl EditorView {
self.clear_completion(editor);
}
+ editor.focus(view_id);
editor.ensure_cursor_in_view(view_id);
return EventResult::Consumed(None);
@@ -1631,7 +1600,7 @@ impl Component for EditorView {
if self.terminal_focused {
(pos, CursorKind::Hidden)
} else {
- // use terminal cursor when terminal loses focus
+ // use crossterm cursor when terminal loses focus
(pos, CursorKind::Underline)
}
}