on master help sign in
Completely remove old Picker and rename FilePicker to Picker
f18acadGokul Soumya
helix-term/src/commands.rs+5−5
@@ -55,8 +55,8 @@ use crate::{
55 job::Callback,
55 job::Callback,
56 keymap::ReverseKeymap,
56 keymap::ReverseKeymap,
57 ui::{
57 ui::{
58− self, editor::InsertEvent, lsp::SignatureHelp, overlay::overlaid, CompletionItem,
58+ self, editor::InsertEvent, lsp::SignatureHelp, overlay::overlaid, CompletionItem, Picker,
59− FilePicker, Picker, Popup, Prompt, PromptEvent,
59+ Popup, Prompt, PromptEvent,
60 },
60 },
61};
61};
62
62
@@ -2156,7 +2156,7 @@ fn global_search(cx: &mut Context) {
2156 return;
2156 return;
2157 }
2157 }
2158
2158
2159− let picker = FilePicker::new(
2159+ let picker = Picker::new(
2160 all_matches,
2160 all_matches,
2161 current_path,
2161 current_path,
2162 move |cx, FileResult { path, line_num }, action| {
2162 move |cx, FileResult { path, line_num }, action| {
@@ -2577,7 +2577,7 @@ fn buffer_picker(cx: &mut Context) {
2577 // mru
2577 // mru
2578 items.sort_unstable_by_key(|item| std::cmp::Reverse(item.focused_at));
2578 items.sort_unstable_by_key(|item| std::cmp::Reverse(item.focused_at));
2579
2579
2580− let picker = FilePicker::new(items, (), |cx, meta, action| {
2580+ let picker = Picker::new(items, (), |cx, meta, action| {
2581 cx.editor.switch(meta.id, action);
2581 cx.editor.switch(meta.id, action);
2582 })
2582 })
2583 .with_preview(|editor, meta| {
2583 .with_preview(|editor, meta| {
@@ -2654,7 +2654,7 @@ fn jumplist_picker(cx: &mut Context) {
2654 }
2654 }
2655 };
2655 };
2656
2656
2657− let picker = FilePicker::new(
2657+ let picker = Picker::new(
2658 cx.editor
2658 cx.editor
2659 .tree
2659 .tree
2660 .views()
2660 .views()
helix-term/src/commands/dap.rs+3−3
@@ -2,7 +2,7 @@ use super::{Context, Editor};
2use crate::{
2use crate::{
3 compositor::{self, Compositor},
3 compositor::{self, Compositor},
4 job::{Callback, Jobs},
4 job::{Callback, Jobs},
5− ui::{self, overlay::overlaid, FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
5+ ui::{self, overlay::overlaid, Picker, Popup, Prompt, PromptEvent, Text},
6};
6};
7use dap::{StackFrame, Thread, ThreadStates};
7use dap::{StackFrame, Thread, ThreadStates};
8use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate};
8use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate};
@@ -73,7 +73,7 @@ fn thread_picker(
73 let debugger = debugger!(editor);
73 let debugger = debugger!(editor);
74
74
75 let thread_states = debugger.thread_states.clone();
75 let thread_states = debugger.thread_states.clone();
76− let picker = FilePicker::new(threads, thread_states, move |cx, thread, _action| {
76+ let picker = Picker::new(threads, thread_states, move |cx, thread, _action| {
77 callback_fn(cx.editor, thread)
77 callback_fn(cx.editor, thread)
78 })
78 })
79 .with_preview(move |editor, thread| {
79 .with_preview(move |editor, thread| {
@@ -726,7 +726,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
726
726
727 let frames = debugger.stack_frames[&thread_id].clone();
727 let frames = debugger.stack_frames[&thread_id].clone();
728
728
729− let picker = FilePicker::new(frames, (), move |cx, frame, _action| {
729+ let picker = Picker::new(frames, (), move |cx, frame, _action| {
730 let debugger = debugger!(cx.editor);
730 let debugger = debugger!(cx.editor);
731 // TODO: this should be simpler to find
731 // TODO: this should be simpler to find
732 let pos = debugger.stack_frames[&thread_id]
732 let pos = debugger.stack_frames[&thread_id]
helix-term/src/commands/lsp.rs+7−7
@@ -31,8 +31,8 @@ use crate::{
31 compositor::{self, Compositor},
31 compositor::{self, Compositor},
32 job::Callback,
32 job::Callback,
33 ui::{
33 ui::{
34− self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, FilePicker,
34+ self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, Picker, Popup,
35− Popup, PromptEvent,
35+ PromptEvent,
36 },
36 },
37};
37};
38
38
@@ -236,11 +236,11 @@ fn jump_to_location(
236 align_view(doc, view, Align::Center);
236 align_view(doc, view, Align::Center);
237}
237}
238
238
239−type SymbolPicker = FilePicker<SymbolInformationItem>;
239+type SymbolPicker = Picker<SymbolInformationItem>;
240
240
241fn sym_picker(symbols: Vec<SymbolInformationItem>, current_path: Option<lsp::Url>) -> SymbolPicker {
241fn sym_picker(symbols: Vec<SymbolInformationItem>, current_path: Option<lsp::Url>) -> SymbolPicker {
242 // TODO: drop current_path comparison and instead use workspace: bool flag?
242 // TODO: drop current_path comparison and instead use workspace: bool flag?
243− FilePicker::new(symbols, current_path.clone(), move |cx, item, action| {
243+ Picker::new(symbols, current_path.clone(), move |cx, item, action| {
244 let (view, doc) = current!(cx.editor);
244 let (view, doc) = current!(cx.editor);
245 push_jump(view, doc);
245 push_jump(view, doc);
246
246
@@ -288,7 +288,7 @@ fn diag_picker(
288 diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize)>>,
288 diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize)>>,
289 current_path: Option<lsp::Url>,
289 current_path: Option<lsp::Url>,
290 format: DiagnosticsFormat,
290 format: DiagnosticsFormat,
291−) -> FilePicker<PickerDiagnostic> {
291+) -> Picker<PickerDiagnostic> {
292 // TODO: drop current_path comparison and instead use workspace: bool flag?
292 // TODO: drop current_path comparison and instead use workspace: bool flag?
293
293
294 // flatten the map to a vec of (url, diag) pairs
294 // flatten the map to a vec of (url, diag) pairs
@@ -314,7 +314,7 @@ fn diag_picker(
314 error: cx.editor.theme.get("error"),
314 error: cx.editor.theme.get("error"),
315 };
315 };
316
316
317− FilePicker::new(
317+ Picker::new(
318 flat_diag,
318 flat_diag,
319 (styles, format),
319 (styles, format),
320 move |cx,
320 move |cx,
@@ -1043,7 +1043,7 @@ fn goto_impl(
1043 editor.set_error("No definition found.");
1043 editor.set_error("No definition found.");
1044 }
1044 }
1045 _locations => {
1045 _locations => {
1046− let picker = FilePicker::new(locations, cwdir, move |cx, location, action| {
1046+ let picker = Picker::new(locations, cwdir, move |cx, location, action| {
1047 jump_to_location(cx.editor, location, offset_encoding, action)
1047 jump_to_location(cx.editor, location, offset_encoding, action)
1048 })
1048 })
1049 .with_preview(move |_editor, location| Some(location_to_file_location(location)));
1049 .with_preview(move |_editor, location| Some(location_to_file_location(location)));
helix-term/src/ui/mod.rs+3−3
@@ -21,7 +21,7 @@ pub use completion::{Completion, CompletionItem};
21pub use editor::EditorView;
21pub use editor::EditorView;
22pub use markdown::Markdown;
22pub use markdown::Markdown;
23pub use menu::Menu;
23pub use menu::Menu;
24−pub use picker::{DynamicPicker, FileLocation, FilePicker, Picker};
24+pub use picker::{DynamicPicker, FileLocation, Picker};
25pub use popup::Popup;
25pub use popup::Popup;
26pub use prompt::{Prompt, PromptEvent};
26pub use prompt::{Prompt, PromptEvent};
27pub use spinner::{ProgressSpinners, Spinner};
27pub use spinner::{ProgressSpinners, Spinner};
@@ -158,7 +158,7 @@ pub fn regex_prompt(
158 cx.push_layer(Box::new(prompt));
158 cx.push_layer(Box::new(prompt));
159}
159}
160
160
161−pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker<PathBuf> {
161+pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker<PathBuf> {
162 use ignore::{types::TypesBuilder, WalkBuilder};
162 use ignore::{types::TypesBuilder, WalkBuilder};
163 use std::time::Instant;
163 use std::time::Instant;
164
164
@@ -217,7 +217,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
217
217
218 log::debug!("file_picker init {:?}", Instant::now().duration_since(now));
218 log::debug!("file_picker init {:?}", Instant::now().duration_since(now));
219
219
220− FilePicker::new(files, root, move |cx, path: &PathBuf, action| {
220+ Picker::new(files, root, move |cx, path: &PathBuf, action| {
221 if let Err(e) = cx.editor.open(path, action) {
221 if let Err(e) = cx.editor.open(path, action) {
222 let err = if let Some(err) = e.source() {
222 let err = if let Some(err) = e.source() {
223 format!("{}", err)
223 format!("{}", err)
helix-term/src/ui/picker.rs+9−124
@@ -114,7 +114,7 @@ impl Preview<'_, '_> {
114 }
114 }
115}
115}
116
116
117−pub struct FilePicker<T: Item> {
117+pub struct Picker<T: Item> {
118 options: Vec<T>,
118 options: Vec<T>,
119 editor_data: T::Data,
119 editor_data: T::Data,
120 // filter: String,
120 // filter: String,
@@ -135,7 +135,6 @@ pub struct FilePicker<T: Item> {
135
135
136 callback_fn: PickerCallback<T>,
136 callback_fn: PickerCallback<T>,
137
137
138− picker: Picker<T>,
139 pub truncate_start: bool,
138 pub truncate_start: bool,
140 /// Caches paths to documents
139 /// Caches paths to documents
141 preview_cache: HashMap<PathBuf, CachedPreview>,
140 preview_cache: HashMap<PathBuf, CachedPreview>,
@@ -144,7 +143,7 @@ pub struct FilePicker<T: Item> {
144 file_fn: Option<FileCallback<T>>,
143 file_fn: Option<FileCallback<T>>,
145}
144}
146
145
147−impl<T: Item + 'static> FilePicker<T> {
146+impl<T: Item + 'static> Picker<T> {
148 pub fn new(
147 pub fn new(
149 options: Vec<T>,
148 options: Vec<T>,
150 editor_data: T::Data,
149 editor_data: T::Data,
@@ -173,8 +172,6 @@ impl<T: Item + 'static> FilePicker<T> {
173 preview_cache: HashMap::new(),
172 preview_cache: HashMap::new(),
174 read_buffer: Vec::with_capacity(1024),
173 read_buffer: Vec::with_capacity(1024),
175 file_fn: None,
174 file_fn: None,
176−
177− picker: unimplemented!(),
178 };
175 };
179
176
180 picker.calculate_column_widths();
177 picker.calculate_column_widths();
@@ -197,7 +194,6 @@ impl<T: Item + 'static> FilePicker<T> {
197
194
198 pub fn truncate_start(mut self, truncate_start: bool) -> Self {
195 pub fn truncate_start(mut self, truncate_start: bool) -> Self {
199 self.truncate_start = truncate_start;
196 self.truncate_start = truncate_start;
200− self.picker.truncate_start = truncate_start;
201 self
197 self
202 }
198 }
203
199
@@ -377,8 +373,7 @@ impl<T: Item + 'static> FilePicker<T> {
377 }
373 }
378
374
379 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
375 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
380− self.picker
381− .selection()
376+ self.selection()
382 .and_then(|current| (self.file_fn.as_ref()?)(editor, current))
377 .and_then(|current| (self.file_fn.as_ref()?)(editor, current))
383 .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line)))
378 .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line)))
384 }
379 }
@@ -849,13 +844,9 @@ impl<T: Item + 'static> FilePicker<T> {
849 self.completion_height = height.saturating_sub(4);
844 self.completion_height = height.saturating_sub(4);
850 Some((width, height))
845 Some((width, height))
851 }
846 }
852−
853− fn id(&self) -> Option<&'static str> {
854− Some("file-picker")
855− }
856}
847}
857
848
858−impl<T: Item + 'static> Component for FilePicker<T> {
849+impl<T: Item + 'static> Component for Picker<T> {
859 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
850 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
860 // +---------+ +---------+
851 // +---------+ +---------+
861 // |prompt | |preview |
852 // |prompt | |preview |
@@ -864,7 +855,7 @@ impl<T: Item + 'static> Component for FilePicker<T> {
864 // | | | |
855 // | | | |
865 // +---------+ +---------+
856 // +---------+ +---------+
866
857
867− let render_preview = self.picker.show_preview && area.width > MIN_AREA_WIDTH_FOR_PREVIEW;
858+ let render_preview = self.show_preview && area.width > MIN_AREA_WIDTH_FOR_PREVIEW;
868
859
869 let picker_width = if render_preview {
860 let picker_width = if render_preview {
870 area.width / 2
861 area.width / 2
@@ -909,112 +900,6 @@ impl Ord for PickerMatch {
909
900
910type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;
901type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;
911
902
912−pub struct Picker<T: Item> {
913− options: Vec<T>,
914− editor_data: T::Data,
915− // filter: String,
916− matcher: Box<Matcher>,
917− matches: Vec<PickerMatch>,
918−
919− /// Current height of the completions box
920− completion_height: u16,
921−
922− cursor: usize,
923− // pattern: String,
924− prompt: Prompt,
925− previous_pattern: (String, FuzzyQuery),
926− /// Whether to truncate the start (default true)
927− pub truncate_start: bool,
928− /// Whether to show the preview panel (default true)
929− show_preview: bool,
930− /// Constraints for tabular formatting
931− widths: Vec<Constraint>,
932−
933− callback_fn: PickerCallback<T>,
934−}
935−
936−impl<T: Item> Picker<T> {
937− pub fn new(
938− options: Vec<T>,
939− editor_data: T::Data,
940− callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
941− ) -> Self {
942− unimplemented!()
943− }
944−
945− pub fn set_options(&mut self, new_options: Vec<T>) {
946− unimplemented!()
947− }
948−
949− pub fn score(&mut self) {
950− unimplemented!()
951− }
952−
953− pub fn force_score(&mut self) {
954− unimplemented!()
955− }
956−
957− /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
958− pub fn move_by(&mut self, amount: usize, direction: Direction) {
959− unimplemented!()
960− }
961−
962− /// Move the cursor down by exactly one page. After the last page comes the first page.
963− pub fn page_up(&mut self) {
964− unimplemented!()
965− }
966−
967− /// Move the cursor up by exactly one page. After the first page comes the last page.
968− pub fn page_down(&mut self) {
969− unimplemented!()
970− }
971−
972− /// Move the cursor to the first entry
973− pub fn to_start(&mut self) {
974− unimplemented!()
975− }
976−
977− /// Move the cursor to the last entry
978− pub fn to_end(&mut self) {
979− unimplemented!()
980− }
981−
982− pub fn selection(&self) -> Option<&T> {
983− unimplemented!()
984− }
985−
986− pub fn toggle_preview(&mut self) {
987− unimplemented!()
988− }
989−
990− fn prompt_handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
991− unimplemented!()
992− }
993−}
994−
995−// process:
996−// - read all the files into a list, maxed out at a large value
997−// - on input change:
998−// - score all the names in relation to input
999−
1000−impl<T: Item + 'static> Component for Picker<T> {
1001− fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
1002− unimplemented!()
1003− }
1004−
1005− fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
1006− unimplemented!()
1007− }
1008−
1009− fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
1010− unimplemented!()
1011− }
1012−
1013− fn cursor(&self, area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
1014− unimplemented!()
1015− }
1016−}
1017−
1018/// Returns a new list of options to replace the contents of the picker
903/// Returns a new list of options to replace the contents of the picker
1019/// when called with the current picker query,
904/// when called with the current picker query,
1020pub type DynQueryCallback<T> =
905pub type DynQueryCallback<T> =
@@ -1023,7 +908,7 @@ pub type DynQueryCallback<T> =
1023/// A picker that updates its contents via a callback whenever the
908/// A picker that updates its contents via a callback whenever the
1024/// query string changes. Useful for live grep, workspace symbols, etc.
909/// query string changes. Useful for live grep, workspace symbols, etc.
1025pub struct DynamicPicker<T: ui::menu::Item + Send> {
910pub struct DynamicPicker<T: ui::menu::Item + Send> {
1026− file_picker: FilePicker<T>,
911+ file_picker: Picker<T>,
1027 query_callback: DynQueryCallback<T>,
912 query_callback: DynQueryCallback<T>,
1028 query: String,
913 query: String,
1029}
914}
@@ -1031,7 +916,7 @@ pub struct DynamicPicker<T: ui::menu::Item + Send> {
1031impl<T: ui::menu::Item + Send> DynamicPicker<T> {
916impl<T: ui::menu::Item + Send> DynamicPicker<T> {
1032 pub const ID: &'static str = "dynamic-picker";
917 pub const ID: &'static str = "dynamic-picker";
1033
918
1034− pub fn new(file_picker: FilePicker<T>, query_callback: DynQueryCallback<T>) -> Self {
919+ pub fn new(file_picker: Picker<T>, query_callback: DynQueryCallback<T>) -> Self {
1035 Self {
920 Self {
1036 file_picker,
921 file_picker,
1037 query_callback,
922 query_callback,
@@ -1047,7 +932,7 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> {
1047
932
1048 fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
933 fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
1049 let event_result = self.file_picker.handle_event(event, cx);
934 let event_result = self.file_picker.handle_event(event, cx);
1050− let current_query = self.file_picker.picker.prompt.line();
935+ let current_query = self.file_picker.prompt.line();
1051
936
1052 if !matches!(event, Event::IdleTimeout) || self.query == *current_query {
937 if !matches!(event, Event::IdleTimeout) || self.query == *current_query {
1053 return event_result;
938 return event_result;
@@ -1063,7 +948,7 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> {
1063 // Wrapping of pickers in overlay is done outside the picker code,
948 // Wrapping of pickers in overlay is done outside the picker code,
1064 // so this is fragile and will break if wrapped in some other widget.
949 // so this is fragile and will break if wrapped in some other widget.
1065 let picker = match compositor.find_id::<Overlay<DynamicPicker<T>>>(Self::ID) {
950 let picker = match compositor.find_id::<Overlay<DynamicPicker<T>>>(Self::ID) {
1066− Some(overlay) => &mut overlay.content.file_picker.picker,
951+ Some(overlay) => &mut overlay.content.file_picker,
1067 None => return,
952 None => return,
1068 };
953 };
1069 picker.set_options(new_options);
954 picker.set_options(new_options);