From 90bc020af67a95eeb1b1c14c29e186e0dc656095 Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Sun, 27 Nov 2022 16:35:29 +0000 Subject: [PATCH] remove default_item from new --- helix-term/src/commands.rs | 27 +++++++++++---------------- helix-term/src/commands/dap.rs | 1 - helix-term/src/commands/typed.rs | 11 +++-------- helix-term/src/ui/picker.rs | 22 ++++++++-------------- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7f5183c99cd72..75cf3ec0b65ad 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2500,22 +2500,17 @@ pub fn command_palette(cx: &mut Context) { } })); - let picker = Picker::new( - commands, - keymap, - move |cx, command, _action| { - let mut ctx = Context { - register: None, - count: std::num::NonZeroUsize::new(1), - editor: cx.editor, - callback: None, - on_next_key_callback: None, - jobs: cx.jobs, - }; - command.execute(&mut ctx); - }, - None, - ); + let picker = Picker::new(commands, keymap, move |cx, command, _action| { + let mut ctx = Context { + register: None, + count: std::num::NonZeroUsize::new(1), + editor: cx.editor, + callback: None, + on_next_key_callback: None, + jobs: cx.jobs, + }; + command.execute(&mut ctx); + }); compositor.push(Box::new(overlayed(picker))); }, )); diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 959b7c3069d6f..cfffea02a3bb2 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -287,7 +287,6 @@ pub fn dap_launch(cx: &mut Context) { }); cx.jobs.callback(callback); }, - None, )))); } diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 3ca646c38da09..351692fd24dfb 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1138,14 +1138,9 @@ fn lsp_workspace_command( let callback = async move { let call: job::Callback = Callback::EditorCompositor(Box::new( move |_editor: &mut Editor, compositor: &mut Compositor| { - let picker = ui::Picker::new( - commands, - (), - |cx, command, _action| { - execute_lsp_command(cx.editor, command.clone()); - }, - None, - ); + let picker = ui::Picker::new(commands, (), |cx, command, _action| { + execute_lsp_command(cx.editor, command.clone()); + }); compositor.push(Box::new(overlayed(picker))) }, )); diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index c371f45f6a80b..b23ed21e700cd 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -115,7 +115,8 @@ impl FilePicker { initial_cursor: Option, ) -> Self { let truncate_start = true; - let mut picker = Picker::new(options, editor_data, callback_fn, initial_cursor); + let mut picker = + Picker::new(options, editor_data, callback_fn).with_default_item(initial_cursor); picker.truncate_start = truncate_start; Self { @@ -392,7 +393,6 @@ impl Picker { options: Vec, editor_data: T::Data, callback_fn: impl Fn(&mut Context, &T, Action) + 'static, - default_item: Option, ) -> Self { let prompt = Prompt::new( "".into(), @@ -413,7 +413,7 @@ impl Picker { show_preview: true, callback_fn: Box::new(callback_fn), completion_height: 0, - default_item, + default_item: None, }; picker.cursor = picker.find_default_item_index().unwrap_or(0); @@ -433,6 +433,11 @@ impl Picker { picker } + pub fn with_default_item(mut self, default_item: Option) -> Self { + self.default_item = default_item; + self + } + pub fn score(&mut self) { let now = Instant::now(); @@ -555,17 +560,6 @@ impl Picker { self.cursor = self.matches.len().saturating_sub(1); } - pub fn set_cursor(&mut self, cursor: usize) { - let len = self.matches.len(); - - if len == 0 { - // No results, can't move. - return; - } - - self.cursor = cursor % len; - } - pub fn selection(&self) -> Option<&T> { self.matches .get(self.cursor)