@@ -17,7 +17,6 @@ use helix_core::{
18use helix_view::{
18use helix_view::{
19 document::{Mode, SCRATCH_BUFFER_NAME},
19 document::{Mode, SCRATCH_BUFFER_NAME},
20− editor::{Config, LineNumber},
21 graphics::{CursorKind, Modifier, Rect, Style},
20 graphics::{CursorKind, Modifier, Rect, Style},
22 info::Info,
21 info::Info,
23 input::KeyEvent,
22 input::KeyEvent,
@@ -421,97 +420,12 @@ impl EditorView {
421 .map(|range| range.cursor_line(text))
420 .map(|range| range.cursor_line(text))
422 .collect();
421 .collect();
424− use std::fmt::Write;
426− fn diagnostic<'doc>(
427− doc: &'doc Document,
433− ) -> GutterFn<'doc> {
434− let warning = theme.get("warning");
435− let error = theme.get("error");
436− let info = theme.get("info");
437− let hint = theme.get("hint");
438− let diagnostics = doc.diagnostics();
440− Box::new(move |line: usize, _selected: bool, out: &mut String| {
441− use helix_core::diagnostic::Severity;
442− if let Some(diagnostic) = diagnostics.iter().find(|d| d.line == line) {
443− write!(out, "●").unwrap();
444− return Some(match diagnostic.severity {
445− Some(Severity::Error) => error,
446− Some(Severity::Warning) | None => warning,
447− Some(Severity::Info) => info,
448− Some(Severity::Hint) => hint,
455− fn line_number<'doc>(
456− doc: &'doc Document,
462− ) -> GutterFn<'doc> {
463− let text = doc.text().slice(..);
464− let last_line = view.last_line(doc);
465− // Whether to draw the line number for the last line of the
466− // document or not. We only draw it if it's not an empty line.
467− let draw_last = text.line_to_byte(last_line) < text.len_bytes();
469− let linenr = theme.get("ui.linenr");
470− let linenr_select: Style = theme.try_get("ui.linenr.selected").unwrap_or(linenr);
472− let current_line = doc
474− .char_to_line(doc.selection(view.id).primary().cursor(text));
476− let config = config.line_number;
478− Box::new(move |line: usize, selected: bool, out: &mut String| {
479− if line == last_line && !draw_last {
480− write!(out, "{:>1$}", '~', width).unwrap();
483− let line = match config {
484− LineNumber::Absolute => line + 1,
485− LineNumber::Relative => {
486− if current_line == line {
489− abs_diff(current_line, line)
493− let style = if selected && is_focused {
498− write!(out, "{:>1$}", line, width).unwrap();
504− type GutterFn<'doc> = Box<dyn Fn(usize, bool, &mut String) -> Option<Style> + 'doc>;
506− for<'doc> fn(&'doc Document, &View, &Theme, &Config, bool, usize) -> GutterFn<'doc>;
507− let gutters: &[(Gutter, usize)] = &[(diagnostic, 1), (line_number, 5)];
509 let mut offset = 0;
423 let mut offset = 0;
511 // avoid lots of small allocations by reusing a text buffer for each line
425 // avoid lots of small allocations by reusing a text buffer for each line
512 let mut text = String::with_capacity(8);
426 let mut text = String::with_capacity(8);
514− for (constructor, width) in gutters {
428+ for (constructor, width) in view.gutters() {
515 let gutter = constructor(doc, view, theme, config, is_focused, *width);
429 let gutter = constructor(doc, view, theme, config, is_focused, *width);
516 text.reserve(*width); // ensure there's enough space for the gutter
430 text.reserve(*width); // ensure there's enough space for the gutter
517 for (i, line) in (view.offset.row..(last_line + 1)).enumerate() {
431 for (i, line) in (view.offset.row..(last_line + 1)).enumerate() {
@@ -1214,12 +1128,3 @@ fn canonicalize_key(key: &mut KeyEvent) {
1214 key.modifiers.remove(KeyModifiers::SHIFT)
1128 key.modifiers.remove(KeyModifiers::SHIFT)
1219−const fn abs_diff(a: usize, b: usize) -> usize {