From 4940db3e2de21b47a7f867896befbcc5010d231d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 27 Mar 2022 13:59:49 +0900 Subject: [PATCH] Make truncate_start a builder method instead --- helix-term/src/commands/lsp.rs | 6 +++--- helix-term/src/ui/picker.rs | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 530e528a9..19d1084e4 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -71,7 +71,7 @@ fn sym_picker( ) -> FilePicker { // TODO: drop current_path comparison and instead use workspace: bool flag? let current_path2 = current_path.clone(); - let mut picker = FilePicker::new( + let picker = FilePicker::new( symbols, move |symbol| { if current_path.as_ref() == Some(&symbol.location.uri) { @@ -104,8 +104,8 @@ fn sym_picker( } }, move |_editor, symbol| Some(location_to_file_location(&symbol.location)), - ); - picker.truncate_start = false; + ) + .truncate_start(false); picker } diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index a1a22c71b..42c42284c 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -91,15 +91,25 @@ impl FilePicker { callback_fn: impl Fn(&mut Context, &T, Action) + 'static, preview_fn: impl Fn(&Editor, &T) -> Option + 'static, ) -> Self { + let truncate_start = true; + let mut picker = Picker::new(options, format_fn, callback_fn); + picker.truncate_start = truncate_start; + Self { - picker: Picker::new(options, format_fn, callback_fn), - truncate_start: true, + picker, + truncate_start, preview_cache: HashMap::new(), read_buffer: Vec::with_capacity(1024), file_fn: Box::new(preview_fn), } } + pub fn truncate_start(mut self, truncate_start: bool) -> Self { + self.truncate_start = truncate_start; + self.picker.truncate_start = truncate_start; + self + } + fn current_file(&self, editor: &Editor) -> Option { self.picker .selection() @@ -176,7 +186,6 @@ impl Component for FilePicker { }; let picker_area = area.with_width(picker_width); - self.picker.truncate_start = self.truncate_start; self.picker.render(picker_area, surface, cx); if !render_preview {