Compare commits

...

2 Commits

Author SHA1 Message Date
mageowl c65f660977 remove single directory option 2025-04-15 07:59:21 -07:00
mageowl 0df1ec27ce add smart bufferline directories 2025-04-15 07:44:52 -07:00
2 changed files with 87 additions and 23 deletions

View File

@ -31,7 +31,7 @@ use helix_view::{
keyboard::{KeyCode, KeyModifiers},
Document, Editor, Theme, View,
};
use std::{mem::take, num::NonZeroUsize, path::PathBuf, rc::Rc};
use std::{collections::HashMap, mem::take, num::NonZeroUsize, path::PathBuf, rc::Rc};
use tui::{buffer::Buffer as Surface, text::Span};
@ -632,13 +632,90 @@ impl EditorView {
let mut x = viewport.x;
let current_doc = view!(editor).doc;
for doc in editor.documents() {
let path = doc.path().unwrap_or(&scratch);
let fname = path
let mut documents: HashMap<_, _>;
let fnames: HashMap<_, _> = if editor.config().bufferline_show_directories {
documents = editor
.documents()
.map(|doc| {
(
doc.id(),
doc.path().map(|p| {
let mut p = p.clone();
let f = PathBuf::from(p.file_name().unwrap_or_default());
p.pop();
(f, p)
}),
)
})
.collect();
let mut ids: Vec<_> = documents.keys().copied().collect();
let mut to_remove: Vec<usize> = Vec::with_capacity(ids.len());
while !ids.is_empty() {
for (idx, id) in ids.iter().enumerate() {
let Some((current, full)) = &documents[id] else {
log::info!("to remove scratch");
to_remove.push(idx);
continue;
};
if documents
.iter()
.filter_map(|(id, o)| o.as_ref().map(|(p, _)| (id, p)))
.all(|(i, p)| p != current || i == id)
|| full.as_os_str().is_empty()
{
log::info!("to remove idx");
to_remove.push(idx);
}
}
for idx in to_remove.iter().rev() {
log::info!("removed idx");
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)));
}
}
log::info!("completed cycle");
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()
.map(|doc| {
(
doc.id(),
doc.path()
.unwrap_or(&scratch)
.file_name()
.unwrap_or_default()
.to_str()
.unwrap_or_default();
.unwrap_or_default(),
)
})
.collect()
};
for doc in editor.documents() {
let fname = &fnames[&doc.id()];
let style = if current_doc == doc.id() {
bufferline_active
@ -646,20 +723,7 @@ impl EditorView {
bufferline_inactive
};
let text = if editor.config().bufferline_show_parent {
let parent_dir = path
.parent()
.and_then(|p| p.file_name().unwrap_or_default().to_str())
.unwrap_or_default();
format!(
" {}/{}{} ",
parent_dir,
fname,
if doc.is_modified() { "[+]" } else { "" }
)
} else {
format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" })
};
let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" });
let used_width = viewport.x.saturating_sub(x);
let rem_width = surface.area.width.saturating_sub(used_width);

View File

@ -333,7 +333,7 @@ pub struct Config {
/// Persistently display open buffers along the top
pub bufferline: BufferLine,
/// Show the parent directory of files in the bufferline.
pub bufferline_show_parent: bool,
pub bufferline_show_directories: bool,
/// Vertical indent width guides.
pub indent_guides: IndentGuidesConfig,
/// Whether to color modes with different colors. Defaults to `false`.
@ -1001,7 +1001,7 @@ impl Default for Config {
rulers: Vec::new(),
whitespace: WhitespaceConfig::default(),
bufferline: BufferLine::default(),
bufferline_show_parent: false,
bufferline_show_directories: false,
indent_guides: IndentGuidesConfig::default(),
color_modes: false,
soft_wrap: SoftWrap {