diff options
author | Colton Clemmer | 2023-02-10 17:34:18 +0000 |
---|---|---|
committer | GitHub | 2023-02-10 17:34:18 +0000 |
commit | ea3293b4daaa472c363105e3c2c2666a2af82ffc (patch) | |
tree | 2a7d311854e64fa54517fe9dd2b42829fb4f80e7 | |
parent | 1840d775c8d5207f08b0fcc3f2325e337369efe8 (diff) |
Split modification indicator from file statusline elements (#4731)
-rw-r--r-- | helix-term/src/ui/statusline.rs | 29 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 10 |
2 files changed, 28 insertions, 11 deletions
diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index a25b4540..dbb513f8 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -141,6 +141,9 @@ where helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner, helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name, helix_view::editor::StatusLineElement::FileName => render_file_name, + helix_view::editor::StatusLineElement::FileModificationIndicator => { + render_file_modification_indicator + } helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding, helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending, helix_view::editor::StatusLineElement::FileType => render_file_type, @@ -417,16 +420,26 @@ where .as_ref() .map(|p| p.to_string_lossy()) .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into()); - format!( - " {}{} ", - path, - if context.doc.is_modified() { "[+]" } else { "" } - ) + format!(" {} ", path) }; write(context, title, None); } +fn render_file_modification_indicator<F>(context: &mut RenderContext, write: F) +where + F: Fn(&mut RenderContext, String, Option<Style>) + Copy, +{ + let title = (if context.doc.is_modified() { + "[+]" + } else { + " " + }) + .to_string(); + + write(context, title, None); +} + fn render_file_base_name<F>(context: &mut RenderContext, write: F) where F: Fn(&mut RenderContext, String, Option<Style>) + Copy, @@ -437,11 +450,7 @@ where .as_ref() .and_then(|p| p.as_path().file_name().map(|s| s.to_string_lossy())) .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into()); - format!( - " {}{} ", - path, - if context.doc.is_modified() { "[+]" } else { "" } - ) + format!(" {} ", path) }; write(context, title, None); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 042f5bdb..50da3dde 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -414,7 +414,12 @@ impl Default for StatusLineConfig { use StatusLineElement as E; Self { - left: vec![E::Mode, E::Spinner, E::FileName], + left: vec![ + E::Mode, + E::Spinner, + E::FileName, + E::FileModificationIndicator, + ], center: vec![], right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding], separator: String::from("│"), @@ -456,6 +461,9 @@ pub enum StatusLineElement { /// The relative file path, including a dirty flag if it's unsaved FileName, + // The file modification indicator + FileModificationIndicator, + /// The file encoding FileEncoding, |