mirror of https://github.com/helix-editor/helix
add bufferline-directories=always back
parent
c65f660977
commit
a7f748c74d
|
@ -25,7 +25,7 @@ use helix_core::{
|
||||||
use helix_view::{
|
use helix_view::{
|
||||||
annotations::diagnostics::DiagnosticFilter,
|
annotations::diagnostics::DiagnosticFilter,
|
||||||
document::{Mode, SCRATCH_BUFFER_NAME},
|
document::{Mode, SCRATCH_BUFFER_NAME},
|
||||||
editor::{CompleteAction, CursorShapeConfig},
|
editor::{BufferLineDirectories, CompleteAction, CursorShapeConfig},
|
||||||
graphics::{Color, CursorKind, Modifier, Rect, Style},
|
graphics::{Color, CursorKind, Modifier, Rect, Style},
|
||||||
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
|
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
|
||||||
keyboard::{KeyCode, KeyModifiers},
|
keyboard::{KeyCode, KeyModifiers},
|
||||||
|
@ -633,89 +633,120 @@ impl EditorView {
|
||||||
let current_doc = view!(editor).doc;
|
let current_doc = view!(editor).doc;
|
||||||
|
|
||||||
let mut documents: HashMap<_, _>;
|
let mut documents: HashMap<_, _>;
|
||||||
let fnames: HashMap<_, _> = if editor.config().bufferline_show_directories {
|
let mut fnames: HashMap<_, _> = match &editor.config().bufferline_directories {
|
||||||
documents = editor
|
BufferLineDirectories::Smart => {
|
||||||
.documents()
|
documents = editor
|
||||||
.map(|doc| {
|
.documents()
|
||||||
(
|
.map(|doc| {
|
||||||
doc.id(),
|
(
|
||||||
doc.path().map(|p| {
|
doc.id(),
|
||||||
let mut p = p.clone();
|
doc.path().map(|p| {
|
||||||
let f = PathBuf::from(p.file_name().unwrap_or_default());
|
let mut p = p.clone();
|
||||||
p.pop();
|
let f = PathBuf::from(p.file_name().unwrap_or_default());
|
||||||
(f, p)
|
p.pop();
|
||||||
}),
|
(f, p)
|
||||||
)
|
}),
|
||||||
})
|
)
|
||||||
.collect();
|
})
|
||||||
let mut ids: Vec<_> = documents.keys().copied().collect();
|
.collect();
|
||||||
let mut to_remove: Vec<usize> = Vec::with_capacity(ids.len());
|
let mut ids: Vec<_> = documents.keys().copied().collect();
|
||||||
while !ids.is_empty() {
|
let mut to_remove: Vec<usize> = Vec::with_capacity(ids.len());
|
||||||
for (idx, id) in ids.iter().enumerate() {
|
while !ids.is_empty() {
|
||||||
let Some((current, full)) = &documents[id] else {
|
for (idx, id) in ids.iter().enumerate() {
|
||||||
log::info!("to remove scratch");
|
let Some((current, full)) = &documents[id] else {
|
||||||
to_remove.push(idx);
|
to_remove.push(idx);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if documents
|
if documents
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(id, o)| o.as_ref().map(|(p, _)| (id, p)))
|
.filter_map(|(id, o)| o.as_ref().map(|(p, _)| (id, p)))
|
||||||
.all(|(i, p)| p != current || i == id)
|
.all(|(i, p)| p != current || i == id)
|
||||||
|| full.as_os_str().is_empty()
|
|| full.as_os_str().is_empty()
|
||||||
{
|
{
|
||||||
log::info!("to remove idx");
|
to_remove.push(idx);
|
||||||
to_remove.push(idx);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for idx in to_remove.iter().rev() {
|
||||||
|
ids.remove(*idx);
|
||||||
|
}
|
||||||
|
to_remove.clear();
|
||||||
|
|
||||||
|
for id in &ids {
|
||||||
|
let Some((current, mut full)) = documents.remove(id).flatten() else {
|
||||||
|
documents.insert(*id, None);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let mut new = PathBuf::from(full.file_name().unwrap_or_default());
|
||||||
|
new.push(current);
|
||||||
|
full.pop();
|
||||||
|
documents.insert(*id, Some((new, full)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
documents
|
||||||
for idx in to_remove.iter().rev() {
|
.iter()
|
||||||
log::info!("removed idx");
|
.map(|(id, op)| {
|
||||||
ids.remove(*idx);
|
(
|
||||||
}
|
*id,
|
||||||
to_remove.clear();
|
format!(
|
||||||
|
" {}{} ",
|
||||||
for id in &ids {
|
op.as_ref()
|
||||||
let Some((current, mut full)) = documents.remove(id).flatten() else {
|
.map(|(p, _)| p.to_str().unwrap_or_default())
|
||||||
documents.insert(*id, None);
|
.unwrap_or(SCRATCH_BUFFER_NAME),
|
||||||
continue;
|
if editor.document(*id).map_or(false, |d| d.is_modified()) {
|
||||||
};
|
"[+]"
|
||||||
let mut new = PathBuf::from(full.file_name().unwrap_or_default());
|
} else {
|
||||||
new.push(current);
|
""
|
||||||
full.pop();
|
}
|
||||||
documents.insert(*id, Some((new, full)));
|
),
|
||||||
}
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
log::info!("completed cycle");
|
BufferLineDirectories::Never => editor
|
||||||
documents
|
|
||||||
.iter()
|
|
||||||
.map(|(id, op)| {
|
|
||||||
(
|
|
||||||
*id,
|
|
||||||
op.as_ref()
|
|
||||||
.map(|(p, _)| p.to_str().unwrap_or_default())
|
|
||||||
.unwrap_or(SCRATCH_BUFFER_NAME),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
} else {
|
|
||||||
editor
|
|
||||||
.documents()
|
.documents()
|
||||||
.map(|doc| {
|
.map(|doc| {
|
||||||
(
|
(
|
||||||
doc.id(),
|
doc.id(),
|
||||||
doc.path()
|
format!(
|
||||||
.unwrap_or(&scratch)
|
" {}{} ",
|
||||||
.file_name()
|
doc.path()
|
||||||
.unwrap_or_default()
|
.unwrap_or(&scratch)
|
||||||
.to_str()
|
.file_name()
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default()
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or_default(),
|
||||||
|
if doc.is_modified() { "[+]" } else { "" }
|
||||||
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect(),
|
||||||
|
BufferLineDirectories::Always => editor
|
||||||
|
.documents()
|
||||||
|
.map(|doc| {
|
||||||
|
let iter = doc.path().unwrap_or(&scratch);
|
||||||
|
(
|
||||||
|
doc.id(),
|
||||||
|
format!(
|
||||||
|
" {parent}/{fname}{modified} ",
|
||||||
|
parent = iter
|
||||||
|
.parent()
|
||||||
|
.and_then(|p| p.file_name().unwrap_or_default().to_str())
|
||||||
|
.unwrap_or_default(),
|
||||||
|
fname = iter
|
||||||
|
.file_name()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or_default(),
|
||||||
|
modified = if doc.is_modified() { "[+]" } else { "" }
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for doc in editor.documents() {
|
for doc in editor.documents() {
|
||||||
let fname = &fnames[&doc.id()];
|
let text = fnames.remove(&doc.id()).unwrap_or_default();
|
||||||
|
|
||||||
let style = if current_doc == doc.id() {
|
let style = if current_doc == doc.id() {
|
||||||
bufferline_active
|
bufferline_active
|
||||||
|
@ -723,7 +754,6 @@ impl EditorView {
|
||||||
bufferline_inactive
|
bufferline_inactive
|
||||||
};
|
};
|
||||||
|
|
||||||
let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" });
|
|
||||||
let used_width = viewport.x.saturating_sub(x);
|
let used_width = viewport.x.saturating_sub(x);
|
||||||
let rem_width = surface.area.width.saturating_sub(used_width);
|
let rem_width = surface.area.width.saturating_sub(used_width);
|
||||||
|
|
||||||
|
|
|
@ -333,7 +333,7 @@ pub struct Config {
|
||||||
/// Persistently display open buffers along the top
|
/// Persistently display open buffers along the top
|
||||||
pub bufferline: BufferLine,
|
pub bufferline: BufferLine,
|
||||||
/// Show the parent directory of files in the bufferline.
|
/// Show the parent directory of files in the bufferline.
|
||||||
pub bufferline_show_directories: bool,
|
pub bufferline_directories: BufferLineDirectories,
|
||||||
/// Vertical indent width guides.
|
/// Vertical indent width guides.
|
||||||
pub indent_guides: IndentGuidesConfig,
|
pub indent_guides: IndentGuidesConfig,
|
||||||
/// Whether to color modes with different colors. Defaults to `false`.
|
/// Whether to color modes with different colors. Defaults to `false`.
|
||||||
|
@ -682,6 +682,18 @@ pub enum BufferLine {
|
||||||
/// Only if multiple buffers are open
|
/// Only if multiple buffers are open
|
||||||
Multiple,
|
Multiple,
|
||||||
}
|
}
|
||||||
|
/// bufferline directory render modes
|
||||||
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
pub enum BufferLineDirectories {
|
||||||
|
/// Don't render directories
|
||||||
|
#[default]
|
||||||
|
Never,
|
||||||
|
/// Always render one directory
|
||||||
|
Always,
|
||||||
|
/// Only if multiple buffers with the same name are open
|
||||||
|
Smart,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
@ -1001,7 +1013,7 @@ impl Default for Config {
|
||||||
rulers: Vec::new(),
|
rulers: Vec::new(),
|
||||||
whitespace: WhitespaceConfig::default(),
|
whitespace: WhitespaceConfig::default(),
|
||||||
bufferline: BufferLine::default(),
|
bufferline: BufferLine::default(),
|
||||||
bufferline_show_directories: false,
|
bufferline_directories: BufferLineDirectories::default(),
|
||||||
indent_guides: IndentGuidesConfig::default(),
|
indent_guides: IndentGuidesConfig::default(),
|
||||||
color_modes: false,
|
color_modes: false,
|
||||||
soft_wrap: SoftWrap {
|
soft_wrap: SoftWrap {
|
||||||
|
|
Loading…
Reference in New Issue