Completely remove old Picker and rename FilePicker to Picker

pull/7264/head
Gokul Soumya 1 year ago committed by Michael Davis
parent 545acfda88
commit f18acadbd0
No known key found for this signature in database

@ -55,8 +55,8 @@ use crate::{
job::Callback, job::Callback,
keymap::ReverseKeymap, keymap::ReverseKeymap,
ui::{ ui::{
self, editor::InsertEvent, lsp::SignatureHelp, overlay::overlaid, CompletionItem, self, editor::InsertEvent, lsp::SignatureHelp, overlay::overlaid, CompletionItem, Picker,
FilePicker, Picker, Popup, Prompt, PromptEvent, Popup, Prompt, PromptEvent,
}, },
}; };
@ -2156,7 +2156,7 @@ fn global_search(cx: &mut Context) {
return; return;
} }
let picker = FilePicker::new( let picker = Picker::new(
all_matches, all_matches,
current_path, current_path,
move |cx, FileResult { path, line_num }, action| { move |cx, FileResult { path, line_num }, action| {
@ -2577,7 +2577,7 @@ fn buffer_picker(cx: &mut Context) {
// mru // mru
items.sort_unstable_by_key(|item| std::cmp::Reverse(item.focused_at)); 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); cx.editor.switch(meta.id, action);
}) })
.with_preview(|editor, meta| { .with_preview(|editor, meta| {
@ -2654,7 +2654,7 @@ fn jumplist_picker(cx: &mut Context) {
} }
}; };
let picker = FilePicker::new( let picker = Picker::new(
cx.editor cx.editor
.tree .tree
.views() .views()

@ -2,7 +2,7 @@ use super::{Context, Editor};
use crate::{ use crate::{
compositor::{self, Compositor}, compositor::{self, Compositor},
job::{Callback, Jobs}, 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 dap::{StackFrame, Thread, ThreadStates};
use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate}; use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate};
@ -73,7 +73,7 @@ fn thread_picker(
let debugger = debugger!(editor); let debugger = debugger!(editor);
let thread_states = debugger.thread_states.clone(); 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) callback_fn(cx.editor, thread)
}) })
.with_preview(move |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 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); let debugger = debugger!(cx.editor);
// TODO: this should be simpler to find // TODO: this should be simpler to find
let pos = debugger.stack_frames[&thread_id] let pos = debugger.stack_frames[&thread_id]

@ -31,8 +31,8 @@ use crate::{
compositor::{self, Compositor}, compositor::{self, Compositor},
job::Callback, job::Callback,
ui::{ ui::{
self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, FilePicker, self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, Picker, Popup,
Popup, PromptEvent, PromptEvent,
}, },
}; };
@ -236,11 +236,11 @@ fn jump_to_location(
align_view(doc, view, Align::Center); align_view(doc, view, Align::Center);
} }
type SymbolPicker = FilePicker<SymbolInformationItem>; type SymbolPicker = Picker<SymbolInformationItem>;
fn sym_picker(symbols: Vec<SymbolInformationItem>, current_path: Option<lsp::Url>) -> SymbolPicker { fn sym_picker(symbols: Vec<SymbolInformationItem>, current_path: Option<lsp::Url>) -> SymbolPicker {
// TODO: drop current_path comparison and instead use workspace: bool flag? // 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); let (view, doc) = current!(cx.editor);
push_jump(view, doc); push_jump(view, doc);
@ -288,7 +288,7 @@ fn diag_picker(
diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize)>>, diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize)>>,
current_path: Option<lsp::Url>, current_path: Option<lsp::Url>,
format: DiagnosticsFormat, format: DiagnosticsFormat,
) -> FilePicker<PickerDiagnostic> { ) -> Picker<PickerDiagnostic> {
// TODO: drop current_path comparison and instead use workspace: bool flag? // TODO: drop current_path comparison and instead use workspace: bool flag?
// flatten the map to a vec of (url, diag) pairs // flatten the map to a vec of (url, diag) pairs
@ -314,7 +314,7 @@ fn diag_picker(
error: cx.editor.theme.get("error"), error: cx.editor.theme.get("error"),
}; };
FilePicker::new( Picker::new(
flat_diag, flat_diag,
(styles, format), (styles, format),
move |cx, move |cx,
@ -1043,7 +1043,7 @@ fn goto_impl(
editor.set_error("No definition found."); editor.set_error("No definition found.");
} }
_locations => { _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) jump_to_location(cx.editor, location, offset_encoding, action)
}) })
.with_preview(move |_editor, location| Some(location_to_file_location(location))); .with_preview(move |_editor, location| Some(location_to_file_location(location)));

@ -21,7 +21,7 @@ pub use completion::{Completion, CompletionItem};
pub use editor::EditorView; pub use editor::EditorView;
pub use markdown::Markdown; pub use markdown::Markdown;
pub use menu::Menu; pub use menu::Menu;
pub use picker::{DynamicPicker, FileLocation, FilePicker, Picker}; pub use picker::{DynamicPicker, FileLocation, Picker};
pub use popup::Popup; pub use popup::Popup;
pub use prompt::{Prompt, PromptEvent}; pub use prompt::{Prompt, PromptEvent};
pub use spinner::{ProgressSpinners, Spinner}; pub use spinner::{ProgressSpinners, Spinner};
@ -158,7 +158,7 @@ pub fn regex_prompt(
cx.push_layer(Box::new(prompt)); cx.push_layer(Box::new(prompt));
} }
pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker<PathBuf> { pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker<PathBuf> {
use ignore::{types::TypesBuilder, WalkBuilder}; use ignore::{types::TypesBuilder, WalkBuilder};
use std::time::Instant; 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)); 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) { if let Err(e) = cx.editor.open(path, action) {
let err = if let Some(err) = e.source() { let err = if let Some(err) = e.source() {
format!("{}", err) format!("{}", err)

@ -114,7 +114,7 @@ impl Preview<'_, '_> {
} }
} }
pub struct FilePicker<T: Item> { pub struct Picker<T: Item> {
options: Vec<T>, options: Vec<T>,
editor_data: T::Data, editor_data: T::Data,
// filter: String, // filter: String,
@ -135,7 +135,6 @@ pub struct FilePicker<T: Item> {
callback_fn: PickerCallback<T>, callback_fn: PickerCallback<T>,
picker: Picker<T>,
pub truncate_start: bool, pub truncate_start: bool,
/// Caches paths to documents /// Caches paths to documents
preview_cache: HashMap<PathBuf, CachedPreview>, preview_cache: HashMap<PathBuf, CachedPreview>,
@ -144,7 +143,7 @@ pub struct FilePicker<T: Item> {
file_fn: Option<FileCallback<T>>, file_fn: Option<FileCallback<T>>,
} }
impl<T: Item + 'static> FilePicker<T> { impl<T: Item + 'static> Picker<T> {
pub fn new( pub fn new(
options: Vec<T>, options: Vec<T>,
editor_data: T::Data, editor_data: T::Data,
@ -173,8 +172,6 @@ impl<T: Item + 'static> FilePicker<T> {
preview_cache: HashMap::new(), preview_cache: HashMap::new(),
read_buffer: Vec::with_capacity(1024), read_buffer: Vec::with_capacity(1024),
file_fn: None, file_fn: None,
picker: unimplemented!(),
}; };
picker.calculate_column_widths(); picker.calculate_column_widths();
@ -197,7 +194,6 @@ impl<T: Item + 'static> FilePicker<T> {
pub fn truncate_start(mut self, truncate_start: bool) -> Self { pub fn truncate_start(mut self, truncate_start: bool) -> Self {
self.truncate_start = truncate_start; self.truncate_start = truncate_start;
self.picker.truncate_start = truncate_start;
self self
} }
@ -377,8 +373,7 @@ impl<T: Item + 'static> FilePicker<T> {
} }
fn current_file(&self, editor: &Editor) -> Option<FileLocation> { fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
self.picker self.selection()
.selection()
.and_then(|current| (self.file_fn.as_ref()?)(editor, current)) .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))) .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line)))
} }
@ -849,13 +844,9 @@ impl<T: Item + 'static> FilePicker<T> {
self.completion_height = height.saturating_sub(4); self.completion_height = height.saturating_sub(4);
Some((width, height)) Some((width, height))
} }
fn id(&self) -> Option<&'static str> {
Some("file-picker")
}
} }
impl<T: Item + 'static> Component for FilePicker<T> { impl<T: Item + 'static> Component for Picker<T> {
fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
// +---------+ +---------+ // +---------+ +---------+
// |prompt | |preview | // |prompt | |preview |
@ -864,7 +855,7 @@ impl<T: Item + 'static> Component for FilePicker<T> {
// | | | | // | | | |
// +---------+ +---------+ // +---------+ +---------+
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 { let picker_width = if render_preview {
area.width / 2 area.width / 2
@ -909,112 +900,6 @@ impl Ord for PickerMatch {
type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>; type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;
pub struct Picker<T: Item> {
options: Vec<T>,
editor_data: T::Data,
// filter: String,
matcher: Box<Matcher>,
matches: Vec<PickerMatch>,
/// 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<Constraint>,
callback_fn: PickerCallback<T>,
}
impl<T: Item> Picker<T> {
pub fn new(
options: Vec<T>,
editor_data: T::Data,
callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
) -> Self {
unimplemented!()
}
pub fn set_options(&mut self, new_options: Vec<T>) {
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<T: Item + 'static> Component for Picker<T> {
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<Position>, CursorKind) {
unimplemented!()
}
}
/// Returns a new list of options to replace the contents of the picker /// Returns a new list of options to replace the contents of the picker
/// when called with the current picker query, /// when called with the current picker query,
pub type DynQueryCallback<T> = pub type DynQueryCallback<T> =
@ -1023,7 +908,7 @@ pub type DynQueryCallback<T> =
/// A picker that updates its contents via a callback whenever the /// A picker that updates its contents via a callback whenever the
/// query string changes. Useful for live grep, workspace symbols, etc. /// query string changes. Useful for live grep, workspace symbols, etc.
pub struct DynamicPicker<T: ui::menu::Item + Send> { pub struct DynamicPicker<T: ui::menu::Item + Send> {
file_picker: FilePicker<T>, file_picker: Picker<T>,
query_callback: DynQueryCallback<T>, query_callback: DynQueryCallback<T>,
query: String, query: String,
} }
@ -1031,7 +916,7 @@ pub struct DynamicPicker<T: ui::menu::Item + Send> {
impl<T: ui::menu::Item + Send> DynamicPicker<T> { impl<T: ui::menu::Item + Send> DynamicPicker<T> {
pub const ID: &'static str = "dynamic-picker"; pub const ID: &'static str = "dynamic-picker";
pub fn new(file_picker: FilePicker<T>, query_callback: DynQueryCallback<T>) -> Self { pub fn new(file_picker: Picker<T>, query_callback: DynQueryCallback<T>) -> Self {
Self { Self {
file_picker, file_picker,
query_callback, query_callback,
@ -1047,7 +932,7 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> {
fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
let event_result = self.file_picker.handle_event(event, cx); 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 { if !matches!(event, Event::IdleTimeout) || self.query == *current_query {
return event_result; return event_result;
@ -1063,7 +948,7 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> {
// Wrapping of pickers in overlay is done outside the picker code, // Wrapping of pickers in overlay is done outside the picker code,
// so this is fragile and will break if wrapped in some other widget. // so this is fragile and will break if wrapped in some other widget.
let picker = match compositor.find_id::<Overlay<DynamicPicker<T>>>(Self::ID) { let picker = match compositor.find_id::<Overlay<DynamicPicker<T>>>(Self::ID) {
Some(overlay) => &mut overlay.content.file_picker.picker, Some(overlay) => &mut overlay.content.file_picker,
None => return, None => return,
}; };
picker.set_options(new_options); picker.set_options(new_options);

Loading…
Cancel
Save