From 6492f17e7da54081d9fb3bd2bf6828d0ef7f1a87 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sun, 24 Mar 2024 11:52:57 -0400 Subject: [PATCH] Add a hidden column for the global search line contents We could expand on this in the future to have different preview modes that you can toggle between with C-t. Currently that binding just hides the preview but it could switch between different preview modes and in one mode hide the path and just show the line contents. --- helix-term/src/commands.rs | 17 ++++------------- helix-term/src/ui/picker.rs | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 1df25ba52..b23c52787 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2243,15 +2243,13 @@ fn global_search(cx: &mut Context) { path: PathBuf, /// 0 indexed lines line_num: usize, - line_content: String, } impl FileResult { - fn new(path: &Path, line_num: usize, line_content: String) -> Self { + fn new(path: &Path, line_num: usize) -> Self { Self { path: path.to_path_buf(), line_num, - line_content, } } } @@ -2272,10 +2270,7 @@ fn global_search(cx: &mut Context) { let path = helix_stdx::path::get_relative_path(&item.path); format!("{}:{}", path.to_string_lossy(), item.line_num + 1).into() }), - PickerColumn::new("contents", |item: &FileResult, _| { - item.line_content.as_str().into() - }) - .without_filtering(), + PickerColumn::hidden("contents"), ]; let get_files = |query: &str, @@ -2355,13 +2350,9 @@ fn global_search(cx: &mut Context) { }; let mut stop = false; - let sink = sinks::UTF8(|line_num, line_content| { + let sink = sinks::UTF8(|line_num, _line_content| { stop = injector - .push(FileResult::new( - entry.path(), - line_num as usize - 1, - line_content.to_string(), - )) + .push(FileResult::new(entry.path(), line_num as usize - 1)) .is_err(); Ok(!stop) diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 76a1805a0..6394fb87f 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -191,6 +191,7 @@ pub struct Column { /// `DynamicPicker` uses this so that the dynamic column (for example regex in /// global search) is not used for filtering twice. filter: bool, + hidden: bool, } impl Column { @@ -199,6 +200,19 @@ impl Column { name: name.into(), format, filter: true, + hidden: false, + } + } + + /// A column which does not display any contents + pub fn hidden(name: impl Into>) -> Self { + let format = |_: &T, _: &D| unreachable!(); + + Self { + name: name.into(), + format, + filter: false, + hidden: true, } } @@ -677,6 +691,10 @@ impl Picker { let mut matcher_index = 0; Row::new(self.columns.iter().map(|column| { + if column.hidden { + return Cell::default(); + } + let Some(Constraint::Length(max_width)) = widths.next() else { unreachable!(); }; @@ -757,7 +775,11 @@ impl Picker { let header_style = cx.editor.theme.get("ui.picker.header"); table = table.header(Row::new(self.columns.iter().map(|column| { - Cell::from(Span::styled(Cow::from(&*column.name), header_style)) + if column.hidden { + Cell::default() + } else { + Cell::from(Span::styled(Cow::from(&*column.name), header_style)) + } }))); }