Unnamed repository; edit this file 'description' to name the repository.
feat: Improve look of Global Search Picker (#12855)
Co-authored-by: Poliorcetics <[email protected]> Co-authored-by: Nikita Revenco <[email protected]> Co-authored-by: Michael Davis <[email protected]>
Nik Revenco 2025-02-27
parent 1e8774a · commit 682967d
-rw-r--r--helix-term/src/commands.rs33
1 files changed, 30 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index f3753768..1fb27a39 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -11,7 +11,10 @@ use helix_stdx::{
};
use helix_vcs::{FileChange, Hunk};
pub use lsp::*;
-use tui::text::Span;
+use tui::{
+ text::{Span, Spans},
+ widgets::Cell,
+};
pub use typed::*;
use helix_core::{
@@ -2404,18 +2407,42 @@ fn global_search(cx: &mut Context) {
struct GlobalSearchConfig {
smart_case: bool,
file_picker_config: helix_view::editor::FilePickerConfig,
+ directory_style: Style,
+ number_style: Style,
+ colon_style: Style,
}
let config = cx.editor.config();
let config = GlobalSearchConfig {
smart_case: config.search.smart_case,
file_picker_config: config.file_picker.clone(),
+ directory_style: cx.editor.theme.get("ui.text.directory"),
+ number_style: cx.editor.theme.get("constant.numeric.integer"),
+ colon_style: cx.editor.theme.get("punctuation"),
};
let columns = [
- PickerColumn::new("path", |item: &FileResult, _| {
+ PickerColumn::new("path", |item: &FileResult, config: &GlobalSearchConfig| {
let path = helix_stdx::path::get_relative_path(&item.path);
- format!("{}:{}", path.to_string_lossy(), item.line_num + 1).into()
+
+ let directories = path
+ .parent()
+ .filter(|p| !p.as_os_str().is_empty())
+ .map(|p| format!("{}{}", p.display(), std::path::MAIN_SEPARATOR))
+ .unwrap_or_default();
+
+ let filename = item
+ .path
+ .file_name()
+ .expect("global search paths are normalized (can't end in `..`)")
+ .to_string_lossy();
+
+ Cell::from(Spans::from(vec![
+ Span::styled(directories, config.directory_style),
+ Span::raw(filename),
+ Span::styled(":", config.colon_style),
+ Span::styled((item.line_num + 1).to_string(), config.number_style),
+ ]))
}),
PickerColumn::hidden("contents"),
];