aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/picker.rs
diff options
context:
space:
mode:
authorGokul Soumya2023-06-18 17:27:11 +0000
committerMichael Davis2023-06-18 17:28:26 +0000
commitf18acadbd0d7b15bc314fc3ede99f4546b72d76d (patch)
tree1413d7f13ac317a41e6e520d2af31cfa7e2a9631 /helix-term/src/ui/picker.rs
parent545acfda8884c890b78e586c86e4f7c5f9a15477 (diff)
Completely remove old Picker and rename FilePicker to Picker
Diffstat (limited to 'helix-term/src/ui/picker.rs')
-rw-r--r--helix-term/src/ui/picker.rs133
1 files changed, 9 insertions, 124 deletions
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<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);