Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/ui/picker.rs')
-rw-r--r--helix-term/src/ui/picker.rs67
1 files changed, 24 insertions, 43 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs
index 4f77f8b9..3f3aaba2 100644
--- a/helix-term/src/ui/picker.rs
+++ b/helix-term/src/ui/picker.rs
@@ -258,7 +258,6 @@ pub struct Picker<T: 'static + Send + Sync, D: 'static> {
widths: Vec<Constraint>,
callback_fn: PickerCallback<T>,
- default_action: Action,
pub truncate_start: bool,
/// Caches paths to documents
@@ -309,10 +308,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
F: Fn(&mut Context, &T, Action) + 'static,
{
let columns: Arc<[_]> = columns.into_iter().collect();
- let matcher_columns = columns
- .iter()
- .filter(|col: &&Column<T, D>| col.filter)
- .count() as u32;
+ let matcher_columns = columns.iter().filter(|col| col.filter).count() as u32;
assert!(matcher_columns > 0);
let matcher = Nucleo::new(
Config::DEFAULT,
@@ -386,7 +382,6 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
truncate_start: true,
show_preview: true,
callback_fn: Box::new(callback_fn),
- default_action: Action::Replace,
completion_height: 0,
widths,
preview_cache: HashMap::new(),
@@ -429,11 +424,6 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
self
}
- pub fn with_initial_cursor(mut self, cursor: u32) -> Self {
- self.cursor = cursor;
- self
- }
-
pub fn with_dynamic_query(
mut self,
callback: DynQueryCallback<T, D>,
@@ -450,11 +440,6 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
self
}
- pub fn with_default_action(mut self, action: Action) -> Self {
- self.default_action = action;
- self
- }
-
/// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
pub fn move_by(&mut self, amount: u32, direction: Direction) {
let len = self.matcher.snapshot().matched_item_count();
@@ -610,15 +595,11 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
let preview = std::fs::metadata(&path)
.and_then(|metadata| {
if metadata.is_dir() {
- let files = super::directory_content(&path, editor)?;
+ let files = super::directory_content(&path)?;
let file_names: Vec<_> = files
.iter()
- .filter_map(|(file_path, is_dir)| {
- let name = file_path
- .strip_prefix(&path)
- .map(|p| Some(p.as_os_str()))
- .unwrap_or_else(|_| file_path.file_name())?
- .to_string_lossy();
+ .filter_map(|(path, is_dir)| {
+ let name = path.file_name()?.to_string_lossy();
if *is_dir {
Some((format!("{}/", name), true))
} else {
@@ -900,7 +881,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
if let Some((preview, range)) = self.get_preview(cx.editor) {
let doc = match preview.document() {
Some(doc)
- if range.is_none_or(|(start, end)| {
+ if range.map_or(true, |(start, end)| {
start <= end && end <= doc.text().len_lines()
}) =>
{
@@ -1048,23 +1029,23 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
let close_fn = |picker: &mut Self| {
// if the picker is very large don't store it as last_picker to avoid
// excessive memory consumption
- let callback: compositor::Callback =
- if picker.matcher.snapshot().item_count() > 1_000_000 {
- Box::new(|compositor: &mut Compositor, _ctx| {
- // remove the layer
- compositor.pop();
- })
- } else {
- // stop streaming in new items in the background, really we should
- // be restarting the stream somehow once the picker gets
- // reopened instead (like for an FS crawl) that would also remove the
- // need for the special case above but that is pretty tricky
- picker.version.fetch_add(1, atomic::Ordering::Relaxed);
- Box::new(|compositor: &mut Compositor, _ctx| {
- // remove the layer
- compositor.last_picker = compositor.pop();
- })
- };
+ let callback: compositor::Callback = if picker.matcher.snapshot().item_count() > 100_000
+ {
+ Box::new(|compositor: &mut Compositor, _ctx| {
+ // remove the layer
+ compositor.pop();
+ })
+ } else {
+ // stop streaming in new items in the background, really we should
+ // be restarting the stream somehow once the picker gets
+ // reopened instead (like for an FS crawl) that would also remove the
+ // need for the special case above but that is pretty tricky
+ picker.version.fetch_add(1, atomic::Ordering::Relaxed);
+ Box::new(|compositor: &mut Compositor, _ctx| {
+ // remove the layer
+ compositor.last_picker = compositor.pop();
+ })
+ };
EventResult::Consumed(Some(callback))
};
@@ -1090,7 +1071,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
key!(Esc) | ctrl!('c') => return close_fn(self),
alt!(Enter) => {
if let Some(option) = self.selection() {
- (self.callback_fn)(ctx, option, self.default_action);
+ (self.callback_fn)(ctx, option, Action::Replace);
}
}
key!(Enter) => {
@@ -1114,7 +1095,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
self.handle_prompt_change(true);
} else {
if let Some(option) = self.selection() {
- (self.callback_fn)(ctx, option, self.default_action);
+ (self.callback_fn)(ctx, option, Action::Replace);
}
if let Some(history_register) = self.prompt.history_register() {
if let Err(err) = ctx