on master help sign in
Split modification indicator from file statusline elements (#4731)
ea3293bColton Clemmer
helix-term/src/ui/statusline.rs+19−10
@@ -141,6 +141,9 @@ where
141 helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
141 helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
142 helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name,
142 helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name,
143 helix_view::editor::StatusLineElement::FileName => render_file_name,
143 helix_view::editor::StatusLineElement::FileName => render_file_name,
144+ helix_view::editor::StatusLineElement::FileModificationIndicator => {
145+ render_file_modification_indicator
146+ }
144 helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
147 helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
145 helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
148 helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
146 helix_view::editor::StatusLineElement::FileType => render_file_type,
149 helix_view::editor::StatusLineElement::FileType => render_file_type,
@@ -417,16 +420,26 @@ where
417 .as_ref()
420 .as_ref()
418 .map(|p| p.to_string_lossy())
421 .map(|p| p.to_string_lossy())
419 .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
422 .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
420− format!(
423+ format!(" {} ", path)
421− " {}{} ",
422− path,
423− if context.doc.is_modified() { "[+]" } else { "" }
424− )
425 };
424 };
426
425
427 write(context, title, None);
426 write(context, title, None);
428}
427}
429
428
429+fn render_file_modification_indicator<F>(context: &mut RenderContext, write: F)
430+where
431+ F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
432+{
433+ let title = (if context.doc.is_modified() {
434+ "[+]"
435+ } else {
436+ " "
437+ })
438+ .to_string();
439+
440+ write(context, title, None);
441+}
442+
430fn render_file_base_name<F>(context: &mut RenderContext, write: F)
443fn render_file_base_name<F>(context: &mut RenderContext, write: F)
431where
444where
432 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
445 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
@@ -437,11 +450,7 @@ where
437 .as_ref()
450 .as_ref()
438 .and_then(|p| p.as_path().file_name().map(|s| s.to_string_lossy()))
451 .and_then(|p| p.as_path().file_name().map(|s| s.to_string_lossy()))
439 .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
452 .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
440− format!(
453+ format!(" {} ", path)
441− " {}{} ",
442− path,
443− if context.doc.is_modified() { "[+]" } else { "" }
444− )
445 };
454 };
446
455
447 write(context, title, None);
456 write(context, title, None);
helix-view/src/editor.rs+9−1
@@ -414,7 +414,12 @@ impl Default for StatusLineConfig {
414 use StatusLineElement as E;
414 use StatusLineElement as E;
415
415
416 Self {
416 Self {
417+ left: vec![
418+ E::Mode,
419+ E::Spinner,
417− left: vec![E::Mode, E::Spinner, E::FileName],
420+ E::FileName,
421+ E::FileModificationIndicator,
422+ ],
418 center: vec![],
423 center: vec![],
419 right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
424 right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
420 separator: String::from("│"),
425 separator: String::from("│"),
@@ -456,6 +461,9 @@ pub enum StatusLineElement {
456 /// The relative file path, including a dirty flag if it's unsaved
461 /// The relative file path, including a dirty flag if it's unsaved
457 FileName,
462 FileName,
458
463
464+ // The file modification indicator
465+ FileModificationIndicator,
466+
459 /// The file encoding
467 /// The file encoding
460 FileEncoding,
468 FileEncoding,
461
469