Split modification indicator from file statusline elements (#4731)
This commit is contained in:
parent
1840d775c8
commit
ea3293b4da
@ -141,6 +141,9 @@ fn get_render_function<F>(element_id: StatusLineElementID) -> impl Fn(&mut Rende
|
|||||||
helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
|
helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
|
||||||
helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name,
|
helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name,
|
||||||
helix_view::editor::StatusLineElement::FileName => render_file_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::FileEncoding => render_file_encoding,
|
||||||
helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
|
helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
|
||||||
helix_view::editor::StatusLineElement::FileType => render_file_type,
|
helix_view::editor::StatusLineElement::FileType => render_file_type,
|
||||||
@ -417,16 +420,26 @@ fn render_file_name<F>(context: &mut RenderContext, write: F)
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| p.to_string_lossy())
|
.map(|p| p.to_string_lossy())
|
||||||
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
|
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
|
||||||
format!(
|
format!(" {} ", path)
|
||||||
" {}{} ",
|
|
||||||
path,
|
|
||||||
if context.doc.is_modified() { "[+]" } else { "" }
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
write(context, title, None);
|
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)
|
fn render_file_base_name<F>(context: &mut RenderContext, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
||||||
@ -437,11 +450,7 @@ fn render_file_base_name<F>(context: &mut RenderContext, write: F)
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|p| p.as_path().file_name().map(|s| s.to_string_lossy()))
|
.and_then(|p| p.as_path().file_name().map(|s| s.to_string_lossy()))
|
||||||
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
|
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
|
||||||
format!(
|
format!(" {} ", path)
|
||||||
" {}{} ",
|
|
||||||
path,
|
|
||||||
if context.doc.is_modified() { "[+]" } else { "" }
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
write(context, title, None);
|
write(context, title, None);
|
||||||
|
@ -414,7 +414,12 @@ fn default() -> Self {
|
|||||||
use StatusLineElement as E;
|
use StatusLineElement as E;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
left: vec![E::Mode, E::Spinner, E::FileName],
|
left: vec![
|
||||||
|
E::Mode,
|
||||||
|
E::Spinner,
|
||||||
|
E::FileName,
|
||||||
|
E::FileModificationIndicator,
|
||||||
|
],
|
||||||
center: vec![],
|
center: vec![],
|
||||||
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
|
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
|
||||||
separator: String::from("│"),
|
separator: String::from("│"),
|
||||||
@ -456,6 +461,9 @@ pub enum StatusLineElement {
|
|||||||
/// The relative file path, including a dirty flag if it's unsaved
|
/// The relative file path, including a dirty flag if it's unsaved
|
||||||
FileName,
|
FileName,
|
||||||
|
|
||||||
|
// The file modification indicator
|
||||||
|
FileModificationIndicator,
|
||||||
|
|
||||||
/// The file encoding
|
/// The file encoding
|
||||||
FileEncoding,
|
FileEncoding,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user