From 009024a72079868cae737a0cacf694c4a55a6899 Mon Sep 17 00:00:00 2001 From: Em Zhan Date: Mon, 9 Jun 2025 23:28:27 -0500 Subject: [PATCH] Refactor common logic into helper function --- helix-term/src/ui/picker.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index d6c07593a..b8b25ff92 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -1009,12 +1009,7 @@ impl Component for Picker= MIN_AREA_WIDTH_FOR_PREVIEW - && area.height >= MIN_AREA_HEIGHT_FOR_PREVIEW; - let stack_vertically = area.width / 2 < MIN_AREA_WIDTH_FOR_PREVIEW; - + let (render_preview, stack_vertically) = self.get_picker_layout(area); let picker_area = if render_preview { if stack_vertically { area.with_height(area.height / 3) @@ -1158,21 +1153,15 @@ impl Component for Picker= MIN_AREA_WIDTH_FOR_PREVIEW - && area.height >= MIN_AREA_HEIGHT_FOR_PREVIEW; - let stack_vertically = area.width / 2 < MIN_AREA_WIDTH_FOR_PREVIEW; - + let (render_preview, stack_vertically) = self.get_picker_layout(area); let picker_width = if render_preview && !stack_vertically { area.width / 2 } else { area.width }; - let area = inner.clip_left(1).with_height(1).with_width(picker_width); + let prompt_area = inner.clip_left(1).with_height(1).with_width(picker_width); - self.prompt.cursor(area, editor) + self.prompt.cursor(prompt_area, editor) } fn required_size(&mut self, (width, height): (u16, u16)) -> Option<(u16, u16)> { @@ -1190,5 +1179,15 @@ impl Drop for Picker { self.version.fetch_add(1, atomic::Ordering::Relaxed); } } +impl Picker { + fn get_picker_layout(&self, area: Rect) -> (bool, bool) { + let render_preview = self.show_preview + && self.file_fn.is_some() + && area.width >= MIN_AREA_WIDTH_FOR_PREVIEW + && area.height >= MIN_AREA_HEIGHT_FOR_PREVIEW; + let stack_vertically = area.width / 2 < MIN_AREA_WIDTH_FOR_PREVIEW; + return (render_preview, stack_vertically); + } +} type PickerCallback = Box;