Add option to show paths in bufferline when active

pull/11836/head
johannes 2 months ago
parent 162028d444
commit 08135cfbd0

1
Cargo.lock generated

@ -1366,6 +1366,7 @@ dependencies = [
"nucleo", "nucleo",
"once_cell", "once_cell",
"open", "open",
"pathdiff",
"pulldown-cmark", "pulldown-cmark",
"same-file", "same-file",
"serde", "serde",

@ -43,6 +43,7 @@
| `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` | | `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` |
| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` |
| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | | `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` |
| `expand-bufferline` | Set to `true` to show the path instead of the filename in the active bufferline tab | `false` |
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | | `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
| `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` | | `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` |
| `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` | | `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` |

@ -72,6 +72,9 @@ serde = { version = "1.0", features = ["derive"] }
grep-regex = "0.1.13" grep-regex = "0.1.13"
grep-searcher = "0.1.14" grep-searcher = "0.1.14"
# to shorten paths in bufferline
pathdiff = "0.2.1"
[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 [target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
libc = "0.2.159" libc = "0.2.159"

@ -30,7 +30,7 @@ use helix_view::{
keyboard::{KeyCode, KeyModifiers}, keyboard::{KeyCode, KeyModifiers},
Document, Editor, Theme, View, Document, Editor, Theme, View,
}; };
use std::{mem::take, num::NonZeroUsize, path::PathBuf, rc::Rc, sync::Arc}; use std::{mem::take, num::NonZeroUsize, rc::Rc, sync::Arc};
use tui::{buffer::Buffer as Surface, text::Span}; use tui::{buffer::Buffer as Surface, text::Span};
@ -593,7 +593,6 @@ impl EditorView {
/// Render bufferline at the top /// Render bufferline at the top
pub fn render_bufferline(editor: &Editor, viewport: Rect, surface: &mut Surface) { pub fn render_bufferline(editor: &Editor, viewport: Rect, surface: &mut Surface) {
let scratch = PathBuf::from(SCRATCH_BUFFER_NAME); // default filename to use for scratch buffer
surface.clear_with( surface.clear_with(
viewport, viewport,
editor editor
@ -616,13 +615,23 @@ impl EditorView {
let current_doc = view!(editor).doc; let current_doc = view!(editor).doc;
for doc in editor.documents() { for doc in editor.documents() {
let fname = doc let name = doc
.path() .path()
.unwrap_or(&scratch) .and_then(|p| {
.file_name() if editor.config().expand_bufferline && current_doc == doc.id() {
.unwrap_or_default() let working_directory = helix_stdx::env::current_working_dir();
.to_str() let relative_path = pathdiff::diff_paths(p.as_path(), &working_directory);
.unwrap_or_default(); if let Some(rel_path) = relative_path {
return if rel_path.starts_with("..") {
p.to_str().map(|s| s.to_owned())
} else {
rel_path.to_str().map(|s| s.to_owned())
};
}
}
p.file_name().and_then(|s| s.to_str()).map(|s| s.to_owned())
})
.unwrap_or(SCRATCH_BUFFER_NAME.to_owned());
let style = if current_doc == doc.id() { let style = if current_doc == doc.id() {
bufferline_active bufferline_active
@ -630,7 +639,7 @@ impl EditorView {
bufferline_inactive bufferline_inactive
}; };
let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" }); let text = format!(" {}{} ", name, 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);

@ -318,6 +318,8 @@ pub struct Config {
pub whitespace: WhitespaceConfig, pub whitespace: WhitespaceConfig,
/// Persistently display open buffers along the top /// Persistently display open buffers along the top
pub bufferline: BufferLine, pub bufferline: BufferLine,
/// Expand file names in buffer line to paths when tab is focused
pub expand_bufferline: bool,
/// 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`.
@ -965,6 +967,7 @@ impl Default for Config {
rulers: Vec::new(), rulers: Vec::new(),
whitespace: WhitespaceConfig::default(), whitespace: WhitespaceConfig::default(),
bufferline: BufferLine::default(), bufferline: BufferLine::default(),
expand_bufferline: false,
indent_guides: IndentGuidesConfig::default(), indent_guides: IndentGuidesConfig::default(),
color_modes: false, color_modes: false,
soft_wrap: SoftWrap { soft_wrap: SoftWrap {

Loading…
Cancel
Save