Skip to content

Commit 499d629

Browse files
committed
Show path in file picker and explorer
The file picker and explorer can each be opened in several ways, each causing it to have a different root path. What's more, the file explorer can change its path while you have it open. This can make it very difficult to keep track of the root directory for these pickers, so we add it as a header. If desired, we could alternatively make this a configuration option, but I see little downside to always including it.
1 parent c36ed6a commit 499d629

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

helix-term/src/ui/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
235235
log::debug!("file_picker init {:?}", Instant::now().duration_since(now));
236236

237237
let columns = [PickerColumn::new(
238-
"path",
238+
root.to_string_lossy(),
239239
|item: &PathBuf, root: &PathBuf| {
240240
item.strip_prefix(root)
241241
.unwrap_or(item)
@@ -253,6 +253,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
253253
cx.editor.set_error(err);
254254
}
255255
})
256+
.always_show_headers()
256257
.with_preview(|_editor, path| Some((path.as_path().into(), None)));
257258
let injector = picker.injector();
258259
let timeout = std::time::Instant::now() + std::time::Duration::from_millis(30);
@@ -286,7 +287,7 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std
286287
let directory_content = directory_content(&root)?;
287288

288289
let columns = [PickerColumn::new(
289-
"path",
290+
root.to_string_lossy(),
290291
|(path, is_dir): &(PathBuf, bool), (root, directory_style): &(PathBuf, Style)| {
291292
let name = path.strip_prefix(root).unwrap_or(path).to_string_lossy();
292293
if *is_dir {
@@ -324,6 +325,7 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std
324325
}
325326
},
326327
)
328+
.always_show_headers()
327329
.with_preview(|_editor, (path, _is_dir)| Some((path.as_path().into(), None)));
328330

329331
Ok(picker)

helix-term/src/ui/picker.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ type DynQueryCallback<T, D> =
241241
pub struct Picker<T: 'static + Send + Sync, D: 'static> {
242242
columns: Arc<[Column<T, D>]>,
243243
primary_column: usize,
244+
always_show_headers: bool,
244245
editor_data: Arc<D>,
245246
version: Arc<AtomicUsize>,
246247
matcher: Nucleo<T>,
@@ -373,6 +374,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
373374
Self {
374375
columns,
375376
primary_column: default_column,
377+
always_show_headers: false,
376378
matcher,
377379
editor_data,
378380
version,
@@ -424,6 +426,11 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
424426
self
425427
}
426428

429+
pub fn always_show_headers(mut self) -> Self {
430+
self.always_show_headers = true;
431+
self
432+
}
433+
427434
pub fn with_dynamic_query(
428435
mut self,
429436
callback: DynQueryCallback<T, D>,
@@ -818,7 +825,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
818825
.widths(&self.widths);
819826

820827
// -- Header
821-
if self.columns.len() > 1 {
828+
if self.always_show_headers || self.columns.len() > 1 {
822829
let active_column = self.query.active_column(self.prompt.position());
823830
let header_style = cx.editor.theme.get("ui.picker.header");
824831
let header_column_style = cx.editor.theme.get("ui.picker.header.column");

0 commit comments

Comments
 (0)