@@ -17,7 +17,6 @@ use helix_core::{
1717};
1818use helix_view::{
1919 document::{Mode, SCRATCH_BUFFER_NAME},
20− editor::{Config, LineNumber},
2120 graphics::{CursorKind, Modifier, Rect, Style},
2221 info::Info,
2322 input::KeyEvent,
@@ -421,97 +420,12 @@ impl EditorView {
421420 .map(|range| range.cursor_line(text))
422421 .collect();
423422
424− use std::fmt::Write;
425−
426− fn diagnostic<'doc>(
427− doc: &'doc Document,
428− _view: &View,
429− theme: &Theme,
430− _config: &Config,
431− _is_focused: bool,
432− _width: usize,
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();
439−
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,
449− });
450− }
451− None
452− })
453− }
454−
455− fn line_number<'doc>(
456− doc: &'doc Document,
457− view: &View,
458− theme: &Theme,
459− config: &Config,
460− is_focused: bool,
461− width: usize,
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();
468−
469− let linenr = theme.get("ui.linenr");
470− let linenr_select: Style = theme.try_get("ui.linenr.selected").unwrap_or(linenr);
471−
472− let current_line = doc
473− .text()
474− .char_to_line(doc.selection(view.id).primary().cursor(text));
475−
476− let config = config.line_number;
477−
478− Box::new(move |line: usize, selected: bool, out: &mut String| {
479− if line == last_line && !draw_last {
480− write!(out, "{:>1$}", '~', width).unwrap();
481− Some(linenr)
482− } else {
483− let line = match config {
484− LineNumber::Absolute => line + 1,
485− LineNumber::Relative => {
486− if current_line == line {
487− line + 1
488− } else {
489− abs_diff(current_line, line)
490− }
491− }
492− };
493− let style = if selected && is_focused {
494− linenr_select
495− } else {
496− linenr
497− };
498− write!(out, "{:>1$}", line, width).unwrap();
499− Some(style)
500− }
501− })
502− }
503−
504− type GutterFn<'doc> = Box<dyn Fn(usize, bool, &mut String) -> Option<Style> + 'doc>;
505− type Gutter =
506− for<'doc> fn(&'doc Document, &View, &Theme, &Config, bool, usize) -> GutterFn<'doc>;
507− let gutters: &[(Gutter, usize)] = &[(diagnostic, 1), (line_number, 5)];
508−
509423 let mut offset = 0;
510424
511425 // avoid lots of small allocations by reusing a text buffer for each line
512426 let mut text = String::with_capacity(8);
513427
514− for (constructor, width) in gutters {
428+ for (constructor, width) in view.gutters() {
515429 let gutter = constructor(doc, view, theme, config, is_focused, *width);
516430 text.reserve(*width); // ensure there's enough space for the gutter
517431 for (i, line) in (view.offset.row..(last_line + 1)).enumerate() {
@@ -1214,12 +1128,3 @@ fn canonicalize_key(key: &mut KeyEvent) {
12141128 key.modifiers.remove(KeyModifiers::SHIFT)
12151129 }
12161130}
1217−
1218−#[inline]
1219−const fn abs_diff(a: usize, b: usize) -> usize {
1220− if a > b {
1221− a - b
1222− } else {
1223− b - a
1224− }
1225−}