on master help sign in
Completely remove old Picker and rename FilePicker to Picker
commitf18acadbd0d7b15bc314fc3ede99f4546b72d76d authorGokul Soumya <gokulps15@gmail.com> dateSun 18 Jun 2023, 12:27 (3 years ago) parent545acfd
5 files changed+27−142
helix-term/src/commands.rs+5−5 helix-term/src/commands/dap.rs+3−3 helix-term/src/commands/lsp.rs+7−7 helix-term/src/ui/mod.rs+3−3 helix-term/src/ui/picker.rs+9−124
helix-term/src/commands.rs+5−5
@@ -55,8 +55,8 @@ use crate::{
5555 job::Callback,
5656 keymap::ReverseKeymap,
5757 ui::{
58− self, editor::InsertEvent, lsp::SignatureHelp, overlay::overlaid, CompletionItem,
59− FilePicker, Picker, Popup, Prompt, PromptEvent,
58+ self, editor::InsertEvent, lsp::SignatureHelp, overlay::overlaid, CompletionItem, Picker,
59+ Popup, Prompt, PromptEvent,
6060 },
6161};
6262
@@ -2156,7 +2156,7 @@ fn global_search(cx: &mut Context) {
21562156 return;
21572157 }
21582158
2159− let picker = FilePicker::new(
2159+ let picker = Picker::new(
21602160 all_matches,
21612161 current_path,
21622162 move |cx, FileResult { path, line_num }, action| {
@@ -2577,7 +2577,7 @@ fn buffer_picker(cx: &mut Context) {
25772577 // mru
25782578 items.sort_unstable_by_key(|item| std::cmp::Reverse(item.focused_at));
25792579
2580− let picker = FilePicker::new(items, (), |cx, meta, action| {
2580+ let picker = Picker::new(items, (), |cx, meta, action| {
25812581 cx.editor.switch(meta.id, action);
25822582 })
25832583 .with_preview(|editor, meta| {
@@ -2654,7 +2654,7 @@ fn jumplist_picker(cx: &mut Context) {
26542654 }
26552655 };
26562656
2657− let picker = FilePicker::new(
2657+ let picker = Picker::new(
26582658 cx.editor
26592659 .tree
26602660 .views()
helix-term/src/commands/dap.rs+3−3
@@ -2,7 +2,7 @@ use super::{Context, Editor};
22use crate::{
33 compositor::{self, Compositor},
44 job::{Callback, Jobs},
5− ui::{self, overlay::overlaid, FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
5+ ui::{self, overlay::overlaid, Picker, Popup, Prompt, PromptEvent, Text},
66};
77use dap::{StackFrame, Thread, ThreadStates};
88use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate};
@@ -73,7 +73,7 @@ fn thread_picker(
7373 let debugger = debugger!(editor);
7474
7575 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| {
7777 callback_fn(cx.editor, thread)
7878 })
7979 .with_preview(move |editor, thread| {
@@ -726,7 +726,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
726726
727727 let frames = debugger.stack_frames[&thread_id].clone();
728728
729− let picker = FilePicker::new(frames, (), move |cx, frame, _action| {
729+ let picker = Picker::new(frames, (), move |cx, frame, _action| {
730730 let debugger = debugger!(cx.editor);
731731 // TODO: this should be simpler to find
732732 let pos = debugger.stack_frames[&thread_id]
helix-term/src/commands/lsp.rs+7−7
@@ -31,8 +31,8 @@ use crate::{
3131 compositor::{self, Compositor},
3232 job::Callback,
3333 ui::{
34− self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, FilePicker,
35− Popup, PromptEvent,
34+ self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, Picker, Popup,
35+ PromptEvent,
3636 },
3737};
3838
@@ -236,11 +236,11 @@ fn jump_to_location(
236236 align_view(doc, view, Align::Center);
237237}
238238
239−type SymbolPicker = FilePicker<SymbolInformationItem>;
239+type SymbolPicker = Picker<SymbolInformationItem>;
240240
241241fn sym_picker(symbols: Vec<SymbolInformationItem>, current_path: Option<lsp::Url>) -> SymbolPicker {
242242 // 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| {
244244 let (view, doc) = current!(cx.editor);
245245 push_jump(view, doc);
246246
@@ -288,7 +288,7 @@ fn diag_picker(
288288 diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize)>>,
289289 current_path: Option<lsp::Url>,
290290 format: DiagnosticsFormat,
291−) -> FilePicker<PickerDiagnostic> {
291+) -> Picker<PickerDiagnostic> {
292292 // TODO: drop current_path comparison and instead use workspace: bool flag?
293293
294294 // flatten the map to a vec of (url, diag) pairs
@@ -314,7 +314,7 @@ fn diag_picker(
314314 error: cx.editor.theme.get("error"),
315315 };
316316
317− FilePicker::new(
317+ Picker::new(
318318 flat_diag,
319319 (styles, format),
320320 move |cx,
@@ -1043,7 +1043,7 @@ fn goto_impl(
10431043 editor.set_error("No definition found.");
10441044 }
10451045 _locations => {
1046− let picker = FilePicker::new(locations, cwdir, move |cx, location, action| {
1046+ let picker = Picker::new(locations, cwdir, move |cx, location, action| {
10471047 jump_to_location(cx.editor, location, offset_encoding, action)
10481048 })
10491049 .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};
2121pub use editor::EditorView;
2222pub use markdown::Markdown;
2323pub use menu::Menu;
24−pub use picker::{DynamicPicker, FileLocation, FilePicker, Picker};
24+pub use picker::{DynamicPicker, FileLocation, Picker};
2525pub use popup::Popup;
2626pub use prompt::{Prompt, PromptEvent};
2727pub use spinner::{ProgressSpinners, Spinner};
@@ -158,7 +158,7 @@ pub fn regex_prompt(
158158 cx.push_layer(Box::new(prompt));
159159}
160160
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> {
162162 use ignore::{types::TypesBuilder, WalkBuilder};
163163 use std::time::Instant;
164164
@@ -217,7 +217,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
217217
218218 log::debug!("file_picker init {:?}", Instant::now().duration_since(now));
219219
220− FilePicker::new(files, root, move |cx, path: &PathBuf, action| {
220+ Picker::new(files, root, move |cx, path: &PathBuf, action| {
221221 if let Err(e) = cx.editor.open(path, action) {
222222 let err = if let Some(err) = e.source() {
223223 format!("{}", err)
helix-term/src/ui/picker.rs+9−124
@@ -114,7 +114,7 @@ impl Preview<'_, '_> {
114114 }
115115}
116116
117−pub struct FilePicker<T: Item> {
117+pub struct Picker<T: Item> {
118118 options: Vec<T>,
119119 editor_data: T::Data,
120120 // filter: String,
@@ -135,7 +135,6 @@ pub struct FilePicker<T: Item> {
135135
136136 callback_fn: PickerCallback<T>,
137137
138− picker: Picker<T>,
139138 pub truncate_start: bool,
140139 /// Caches paths to documents
141140 preview_cache: HashMap<PathBuf, CachedPreview>,
@@ -144,7 +143,7 @@ pub struct FilePicker<T: Item> {
144143 file_fn: Option<FileCallback<T>>,
145144}
146145
147−impl<T: Item + 'static> FilePicker<T> {
146+impl<T: Item + 'static> Picker<T> {
148147 pub fn new(
149148 options: Vec<T>,
150149 editor_data: T::Data,
@@ -173,8 +172,6 @@ impl<T: Item + 'static> FilePicker<T> {
173172 preview_cache: HashMap::new(),
174173 read_buffer: Vec::with_capacity(1024),
175174 file_fn: None,
176−
177− picker: unimplemented!(),
178175 };
179176
180177 picker.calculate_column_widths();
@@ -197,7 +194,6 @@ impl<T: Item + 'static> FilePicker<T> {
197194
198195 pub fn truncate_start(mut self, truncate_start: bool) -> Self {
199196 self.truncate_start = truncate_start;
200− self.picker.truncate_start = truncate_start;
201197 self
202198 }
203199
@@ -377,8 +373,7 @@ impl<T: Item + 'static> FilePicker<T> {
377373 }
378374
379375 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
380− self.picker
381− .selection()
376+ self.selection()
382377 .and_then(|current| (self.file_fn.as_ref()?)(editor, current))
383378 .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line)))
384379 }
@@ -849,13 +844,9 @@ impl<T: Item + 'static> FilePicker<T> {
849844 self.completion_height = height.saturating_sub(4);
850845 Some((width, height))
851846 }
852−
853− fn id(&self) -> Option<&'static str> {
854− Some("file-picker")
855− }
856847}
857848
858−impl<T: Item + 'static> Component for FilePicker<T> {
849+impl<T: Item + 'static> Component for Picker<T> {
859850 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
860851 // +---------+ +---------+
861852 // |prompt | |preview |
@@ -864,7 +855,7 @@ impl<T: Item + 'static> Component for FilePicker<T> {
864855 // | | | |
865856 // +---------+ +---------+
866857
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;
868859
869860 let picker_width = if render_preview {
870861 area.width / 2
@@ -909,112 +900,6 @@ impl Ord for PickerMatch {
909900
910901type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;
911902
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−
1018903/// Returns a new list of options to replace the contents of the picker
1019904/// when called with the current picker query,
1020905pub type DynQueryCallback<T> =
@@ -1023,7 +908,7 @@ pub type DynQueryCallback<T> =
1023908/// A picker that updates its contents via a callback whenever the
1024909/// query string changes. Useful for live grep, workspace symbols, etc.
1025910pub struct DynamicPicker<T: ui::menu::Item + Send> {
1026− file_picker: FilePicker<T>,
911+ file_picker: Picker<T>,
1027912 query_callback: DynQueryCallback<T>,
1028913 query: String,
1029914}
@@ -1031,7 +916,7 @@ pub struct DynamicPicker<T: ui::menu::Item + Send> {
1031916impl<T: ui::menu::Item + Send> DynamicPicker<T> {
1032917 pub const ID: &'static str = "dynamic-picker";
1033918
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 {
1035920 Self {
1036921 file_picker,
1037922 query_callback,
@@ -1047,7 +932,7 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> {
1047932
1048933 fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
1049934 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();
1051936
1052937 if !matches!(event, Event::IdleTimeout) || self.query == *current_query {
1053938 return event_result;
@@ -1063,7 +948,7 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> {
1063948 // Wrapping of pickers in overlay is done outside the picker code,
1064949 // so this is fragile and will break if wrapped in some other widget.
1065950 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,
1067952 None => return,
1068953 };
1069954 picker.set_options(new_options);