Completely remove old Picker and rename FilePicker to Picker

pull/16/head
Gokul Soumya 11 months 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,
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()

@ -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]

@ -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<SymbolInformationItem>;
type SymbolPicker = Picker<SymbolInformationItem>;
fn sym_picker(symbols: Vec<SymbolInformationItem>, current_path: Option<lsp::Url>) -> 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<lsp::Url, Vec<(lsp::Diagnostic, usize)>>,
current_path: Option<lsp::Url>,
format: DiagnosticsFormat,
) -> FilePicker<PickerDiagnostic> {
) -> Picker<PickerDiagnostic> {
// 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)));

@ -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<PathBuf> {
pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker<PathBuf> {
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)

@ -114,7 +114,7 @@ impl Preview<'_, '_> {
}
}
pub struct FilePicker<T: Item> {
pub struct Picker<T: Item> {
options: Vec<T>,
editor_data: T::Data,
// filter: String,
@ -135,7 +135,6 @@ pub struct FilePicker<T: Item> {
callback_fn: PickerCallback<T>,
picker: Picker<T>,
pub truncate_start: bool,
/// Caches paths to documents
preview_cache: HashMap<PathBuf, CachedPreview>,
@ -144,7 +143,7 @@ pub struct FilePicker<T: Item> {
file_fn: Option<FileCallback<T>>,
}
impl<T: Item + 'static> FilePicker<T> {
impl<T: Item + 'static> Picker<T> {
pub fn new(
options: Vec<T>,
editor_data: T::Data,
@ -173,8 +172,6 @@ impl<T: Item + 'static> FilePicker<T> {
preview_cache: HashMap::new(),
read_buffer: Vec::with_capacity(1024),
file_fn: None,
picker: unimplemented!(),
};
picker.calculate_column_widths();
@ -197,7 +194,6 @@ impl<T: Item + 'static> FilePicker<T> {
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<T: Item + 'static> FilePicker<T> {
}
fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
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<T: Item + 'static> FilePicker<T> {
self.completion_height = height.saturating_sub(4);
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) {
// +---------+ +---------+
// |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 {
area.width / 2
@ -909,112 +900,6 @@ impl Ord for PickerMatch {
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
/// when called with the current picker query,
pub type DynQueryCallback<T> =
@ -1023,7 +908,7 @@ pub type DynQueryCallback<T> =
/// A picker that updates its contents via a callback whenever the
/// query string changes. Useful for live grep, workspace symbols, etc.
pub struct DynamicPicker<T: ui::menu::Item + Send> {
file_picker: FilePicker<T>,
file_picker: Picker<T>,
query_callback: DynQueryCallback<T>,
query: String,
}
@ -1031,7 +916,7 @@ pub struct DynamicPicker<T: ui::menu::Item + Send> {
impl<T: ui::menu::Item + Send> DynamicPicker<T> {
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 {
file_picker,
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 {
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<T: Item + Send + 'static> Component for DynamicPicker<T> {
// 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::<Overlay<DynamicPicker<T>>>(Self::ID) {
Some(overlay) => &mut overlay.content.file_picker.picker,
Some(overlay) => &mut overlay.content.file_picker,
None => return,
};
picker.set_options(new_options);

Loading…
Cancel
Save