diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b760b692..2c9295f1 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -55,8 +55,8 @@ use crate::{ job::Callback, keymap::ReverseKeymap, ui::{ - self, editor::InsertEvent, lsp::SignatureHelp, overlay::overlaid, CompletionItem, - FilePicker, Picker, Popup, Prompt, PromptEvent, + self, editor::InsertEvent, lsp::SignatureHelp, overlay::overlaid, CompletionItem, Picker, + Popup, Prompt, PromptEvent, }, }; @@ -2156,7 +2156,7 @@ fn global_search(cx: &mut Context) { return; } - let picker = FilePicker::new( + let picker = Picker::new( all_matches, current_path, move |cx, FileResult { path, line_num }, action| { @@ -2577,7 +2577,7 @@ fn buffer_picker(cx: &mut Context) { // mru items.sort_unstable_by_key(|item| std::cmp::Reverse(item.focused_at)); - let picker = FilePicker::new(items, (), |cx, meta, action| { + let picker = Picker::new(items, (), |cx, meta, action| { cx.editor.switch(meta.id, action); }) .with_preview(|editor, meta| { @@ -2654,7 +2654,7 @@ fn jumplist_picker(cx: &mut Context) { } }; - let picker = FilePicker::new( + let picker = Picker::new( cx.editor .tree .views() diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 2684e946..70a5ec21 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -2,7 +2,7 @@ use super::{Context, Editor}; use crate::{ compositor::{self, Compositor}, job::{Callback, Jobs}, - ui::{self, overlay::overlaid, FilePicker, Picker, Popup, Prompt, PromptEvent, Text}, + ui::{self, overlay::overlaid, Picker, Popup, Prompt, PromptEvent, Text}, }; use dap::{StackFrame, Thread, ThreadStates}; use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate}; @@ -73,7 +73,7 @@ fn thread_picker( let debugger = debugger!(editor); let thread_states = debugger.thread_states.clone(); - let picker = FilePicker::new(threads, thread_states, move |cx, thread, _action| { + let picker = Picker::new(threads, thread_states, move |cx, thread, _action| { callback_fn(cx.editor, thread) }) .with_preview(move |editor, thread| { @@ -726,7 +726,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) { let frames = debugger.stack_frames[&thread_id].clone(); - let picker = FilePicker::new(frames, (), move |cx, frame, _action| { + let picker = Picker::new(frames, (), move |cx, frame, _action| { let debugger = debugger!(cx.editor); // TODO: this should be simpler to find let pos = debugger.stack_frames[&thread_id] diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 7cc2eaf8..55153648 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -31,8 +31,8 @@ use crate::{ compositor::{self, Compositor}, job::Callback, ui::{ - self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, FilePicker, - Popup, PromptEvent, + self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, Picker, Popup, + PromptEvent, }, }; @@ -236,11 +236,11 @@ fn jump_to_location( align_view(doc, view, Align::Center); } -type SymbolPicker = FilePicker; +type SymbolPicker = Picker; fn sym_picker(symbols: Vec, current_path: Option) -> SymbolPicker { // TODO: drop current_path comparison and instead use workspace: bool flag? - FilePicker::new(symbols, current_path.clone(), move |cx, item, action| { + Picker::new(symbols, current_path.clone(), move |cx, item, action| { let (view, doc) = current!(cx.editor); push_jump(view, doc); @@ -288,7 +288,7 @@ fn diag_picker( diagnostics: BTreeMap>, current_path: Option, format: DiagnosticsFormat, -) -> FilePicker { +) -> Picker { // TODO: drop current_path comparison and instead use workspace: bool flag? // flatten the map to a vec of (url, diag) pairs @@ -314,7 +314,7 @@ fn diag_picker( error: cx.editor.theme.get("error"), }; - FilePicker::new( + Picker::new( flat_diag, (styles, format), move |cx, @@ -1043,7 +1043,7 @@ fn goto_impl( editor.set_error("No definition found."); } _locations => { - let picker = FilePicker::new(locations, cwdir, move |cx, location, action| { + let picker = Picker::new(locations, cwdir, move |cx, location, action| { jump_to_location(cx.editor, location, offset_encoding, action) }) .with_preview(move |_editor, location| Some(location_to_file_location(location))); diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index c5e66d86..155f2435 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -21,7 +21,7 @@ pub use completion::{Completion, CompletionItem}; pub use editor::EditorView; pub use markdown::Markdown; pub use menu::Menu; -pub use picker::{DynamicPicker, FileLocation, FilePicker, Picker}; +pub use picker::{DynamicPicker, FileLocation, Picker}; pub use popup::Popup; pub use prompt::{Prompt, PromptEvent}; pub use spinner::{ProgressSpinners, Spinner}; @@ -158,7 +158,7 @@ pub fn regex_prompt( cx.push_layer(Box::new(prompt)); } -pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker { +pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker { use ignore::{types::TypesBuilder, WalkBuilder}; use std::time::Instant; @@ -217,7 +217,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi log::debug!("file_picker init {:?}", Instant::now().duration_since(now)); - FilePicker::new(files, root, move |cx, path: &PathBuf, action| { + Picker::new(files, root, move |cx, path: &PathBuf, action| { if let Err(e) = cx.editor.open(path, action) { let err = if let Some(err) = e.source() { format!("{}", err) diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 001526c4..04ed940c 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -114,7 +114,7 @@ impl Preview<'_, '_> { } } -pub struct FilePicker { +pub struct Picker { options: Vec, editor_data: T::Data, // filter: String, @@ -135,7 +135,6 @@ pub struct FilePicker { callback_fn: PickerCallback, - picker: Picker, pub truncate_start: bool, /// Caches paths to documents preview_cache: HashMap, @@ -144,7 +143,7 @@ pub struct FilePicker { file_fn: Option>, } -impl FilePicker { +impl Picker { pub fn new( options: Vec, editor_data: T::Data, @@ -173,8 +172,6 @@ impl FilePicker { preview_cache: HashMap::new(), read_buffer: Vec::with_capacity(1024), file_fn: None, - - picker: unimplemented!(), }; picker.calculate_column_widths(); @@ -197,7 +194,6 @@ impl FilePicker { pub fn truncate_start(mut self, truncate_start: bool) -> Self { self.truncate_start = truncate_start; - self.picker.truncate_start = truncate_start; self } @@ -377,8 +373,7 @@ impl FilePicker { } fn current_file(&self, editor: &Editor) -> Option { - self.picker - .selection() + self.selection() .and_then(|current| (self.file_fn.as_ref()?)(editor, current)) .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line))) } @@ -849,13 +844,9 @@ impl FilePicker { self.completion_height = height.saturating_sub(4); Some((width, height)) } - - fn id(&self) -> Option<&'static str> { - Some("file-picker") - } } -impl Component for FilePicker { +impl Component for Picker { fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { // +---------+ +---------+ // |prompt | |preview | @@ -864,7 +855,7 @@ impl Component for FilePicker { // | | | | // +---------+ +---------+ - let render_preview = self.picker.show_preview && area.width > MIN_AREA_WIDTH_FOR_PREVIEW; + let render_preview = self.show_preview && area.width > MIN_AREA_WIDTH_FOR_PREVIEW; let picker_width = if render_preview { area.width / 2 @@ -909,112 +900,6 @@ impl Ord for PickerMatch { type PickerCallback = Box; -pub struct Picker { - options: Vec, - editor_data: T::Data, - // filter: String, - matcher: Box, - matches: Vec, - - /// Current height of the completions box - completion_height: u16, - - cursor: usize, - // pattern: String, - prompt: Prompt, - previous_pattern: (String, FuzzyQuery), - /// Whether to truncate the start (default true) - pub truncate_start: bool, - /// Whether to show the preview panel (default true) - show_preview: bool, - /// Constraints for tabular formatting - widths: Vec, - - callback_fn: PickerCallback, -} - -impl Picker { - pub fn new( - options: Vec, - editor_data: T::Data, - callback_fn: impl Fn(&mut Context, &T, Action) + 'static, - ) -> Self { - unimplemented!() - } - - pub fn set_options(&mut self, new_options: Vec) { - unimplemented!() - } - - pub fn score(&mut self) { - unimplemented!() - } - - pub fn force_score(&mut self) { - unimplemented!() - } - - /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`) - pub fn move_by(&mut self, amount: usize, direction: Direction) { - unimplemented!() - } - - /// Move the cursor down by exactly one page. After the last page comes the first page. - pub fn page_up(&mut self) { - unimplemented!() - } - - /// Move the cursor up by exactly one page. After the first page comes the last page. - pub fn page_down(&mut self) { - unimplemented!() - } - - /// Move the cursor to the first entry - pub fn to_start(&mut self) { - unimplemented!() - } - - /// Move the cursor to the last entry - pub fn to_end(&mut self) { - unimplemented!() - } - - pub fn selection(&self) -> Option<&T> { - unimplemented!() - } - - pub fn toggle_preview(&mut self) { - unimplemented!() - } - - fn prompt_handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { - unimplemented!() - } -} - -// process: -// - read all the files into a list, maxed out at a large value -// - on input change: -// - score all the names in relation to input - -impl Component for Picker { - fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { - unimplemented!() - } - - fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { - unimplemented!() - } - - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { - unimplemented!() - } - - fn cursor(&self, area: Rect, editor: &Editor) -> (Option, CursorKind) { - unimplemented!() - } -} - /// Returns a new list of options to replace the contents of the picker /// when called with the current picker query, pub type DynQueryCallback = @@ -1023,7 +908,7 @@ pub type DynQueryCallback = /// A picker that updates its contents via a callback whenever the /// query string changes. Useful for live grep, workspace symbols, etc. pub struct DynamicPicker { - file_picker: FilePicker, + file_picker: Picker, query_callback: DynQueryCallback, query: String, } @@ -1031,7 +916,7 @@ pub struct DynamicPicker { impl DynamicPicker { pub const ID: &'static str = "dynamic-picker"; - pub fn new(file_picker: FilePicker, query_callback: DynQueryCallback) -> Self { + pub fn new(file_picker: Picker, query_callback: DynQueryCallback) -> Self { Self { file_picker, query_callback, @@ -1047,7 +932,7 @@ impl Component for DynamicPicker { fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { let event_result = self.file_picker.handle_event(event, cx); - let current_query = self.file_picker.picker.prompt.line(); + let current_query = self.file_picker.prompt.line(); if !matches!(event, Event::IdleTimeout) || self.query == *current_query { return event_result; @@ -1063,7 +948,7 @@ impl Component for DynamicPicker { // Wrapping of pickers in overlay is done outside the picker code, // so this is fragile and will break if wrapped in some other widget. let picker = match compositor.find_id::>>(Self::ID) { - Some(overlay) => &mut overlay.content.file_picker.picker, + Some(overlay) => &mut overlay.content.file_picker, None => return, }; picker.set_options(new_options);