aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGokul Soumya2023-06-18 16:34:13 +0000
committerMichael Davis2023-06-18 16:34:13 +0000
commit40916dff6355a741f91bc47ca0a3c6443ac2d5a3 (patch)
treef6560d0d041aa8a06df06b2209201b07b138a8df
parentd5af6031f6ccd0a3f32efbb210aec24cd9c71ab1 (diff)
Move FilePicker::render from Component impl to normal impl
Merges the code for the Picker and FilePicker into a single Picker that can show a file preview if a preview callback is provided. This change was mainly made to facilitate refactoring out a simple skeleton of a picker that does not do any filtering to be reused in a normal Picker and a DynamicPicker (see #5714; in particular [mikes-comment] and [gokuls-comment]). The crux of the issue is that a picker maintains a list of predefined options (eg. list of files in the directory) and (re-)filters them every time the picker prompt changes, while a dynamic picker (eg. interactive global search, #4687) recalculates the full list of options on every prompt change. Using a filtering picker to drive a dynamic picker hence does duplicate work of filtering thousands of matches for no reason. It could also cause problems like interfering with the regex pattern in the global search. I tried to directly extract a PickerBase to be reused in Picker and FilePicker and DynamicPicker, but the problem is that DynamicPicker is actually a DynamicFilePicker (i.e. it can preview file contents) which means we would need PickerBase, Picker, FilePicker, DynamicPicker and DynamicFilePicker and then another way of sharing the previewing code between a FilePicker and a DynamicFilePicker. By merging Picker and FilePicker into Picker, we only need PickerBase, Picker and DynamicPicker. [gokuls-comment]: https://github.com/helix-editor/helix/issues/5714#issuecomment-1410949578 [mikes-comment]: https://github.com/helix-editor/helix/issues/5714#issuecomment-1407451963
-rw-r--r--helix-term/src/ui/picker.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs
index d161f786..c357c6d6 100644
--- a/helix-term/src/ui/picker.rs
+++ b/helix-term/src/ui/picker.rs
@@ -269,10 +269,8 @@ impl<T: Item + 'static> FilePicker<T> {
EventResult::Consumed(callback)
}
-}
-impl<T: Item + 'static> Component for FilePicker<T> {
- fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
+ fn render_picker(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
// +---------+ +---------+
// |prompt | |preview |
// +---------+ | |
@@ -416,6 +414,12 @@ impl<T: Item + 'static> Component for FilePicker<T> {
}
}
+impl<T: Item + 'static> Component for FilePicker<T> {
+ fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
+ self.render_picker(area, surface, cx);
+ }
+}
+
#[derive(PartialEq, Eq, Debug)]
struct PickerMatch {
score: i64,