on master help sign in
Split modification indicator from file statusline elements (#4731)
commitea3293b4daaa472c363105e3c2c2666a2af82ffc authorColton Clemmer <cole.clemmer@gmail.com> dateFri 10 Feb 2023, 11:34 (4 years ago) parent1840d77
2 files changed+28−11
helix-term/src/ui/statusline.rs+19−10 helix-view/src/editor.rs+9−1
helix-term/src/ui/statusline.rs+19−10
@@ -141,6 +141,9 @@ where
141141 helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
142142 helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name,
143143 helix_view::editor::StatusLineElement::FileName => render_file_name,
144+ helix_view::editor::StatusLineElement::FileModificationIndicator => {
145+ render_file_modification_indicator
146+ }
144147 helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
145148 helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
146149 helix_view::editor::StatusLineElement::FileType => render_file_type,
@@ -417,16 +420,26 @@ where
417420 .as_ref()
418421 .map(|p| p.to_string_lossy())
419422 .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
420− format!(
421− " {}{} ",
422− path,
423− if context.doc.is_modified() { "[+]" } else { "" }
424− )
423+ format!(" {} ", path)
425424 };
426425
427426 write(context, title, None);
428427}
429428
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+
430443fn render_file_base_name<F>(context: &mut RenderContext, write: F)
431444where
432445 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
@@ -437,11 +450,7 @@ where
437450 .as_ref()
438451 .and_then(|p| p.as_path().file_name().map(|s| s.to_string_lossy()))
439452 .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
440− format!(
441− " {}{} ",
442− path,
443− if context.doc.is_modified() { "[+]" } else { "" }
444− )
453+ format!(" {} ", path)
445454 };
446455
447456 write(context, title, None);
helix-view/src/editor.rs+9−1
@@ -414,7 +414,12 @@ impl Default for StatusLineConfig {
414414 use StatusLineElement as E;
415415
416416 Self {
417− left: vec![E::Mode, E::Spinner, E::FileName],
417+ left: vec![
418+ E::Mode,
419+ E::Spinner,
420+ E::FileName,
421+ E::FileModificationIndicator,
422+ ],
418423 center: vec![],
419424 right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
420425 separator: String::from("│"),
@@ -456,6 +461,9 @@ pub enum StatusLineElement {
456461 /// The relative file path, including a dirty flag if it's unsaved
457462 FileName,
458463
464+ // The file modification indicator
465+ FileModificationIndicator,
466+
459467 /// The file encoding
460468 FileEncoding,
461469