on master help sign in
Make truncate_start a builder method instead
commit4940db3e2de21b47a7f867896befbcc5010d231d authorBlaž Hrastnik <blaz@mxxn.io> dateSun 27 Mar 2022, 13:59 (5 years ago) parent20cf75d
2 files changed+15−6
helix-term/src/commands/lsp.rs+3−3 helix-term/src/ui/picker.rs+12−3
helix-term/src/commands/lsp.rs+3−3
@@ -71,7 +71,7 @@ fn sym_picker(
7171) -> FilePicker<lsp::SymbolInformation> {
7272 // TODO: drop current_path comparison and instead use workspace: bool flag?
7373 let current_path2 = current_path.clone();
74− let mut picker = FilePicker::new(
74+ let picker = FilePicker::new(
7575 symbols,
7676 move |symbol| {
7777 if current_path.as_ref() == Some(&symbol.location.uri) {
@@ -104,8 +104,8 @@ fn sym_picker(
104104 }
105105 },
106106 move |_editor, symbol| Some(location_to_file_location(&symbol.location)),
107− );
108− picker.truncate_start = false;
107+ )
108+ .truncate_start(false);
109109 picker
110110}
111111
helix-term/src/ui/picker.rs+12−3
@@ -91,15 +91,25 @@ impl<T> FilePicker<T> {
9191 callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
9292 preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static,
9393 ) -> Self {
94+ let truncate_start = true;
95+ let mut picker = Picker::new(options, format_fn, callback_fn);
96+ picker.truncate_start = truncate_start;
97+
9498 Self {
95− picker: Picker::new(options, format_fn, callback_fn),
96− truncate_start: true,
99+ picker,
100+ truncate_start,
97101 preview_cache: HashMap::new(),
98102 read_buffer: Vec::with_capacity(1024),
99103 file_fn: Box::new(preview_fn),
100104 }
101105 }
102106
107+ pub fn truncate_start(mut self, truncate_start: bool) -> Self {
108+ self.truncate_start = truncate_start;
109+ self.picker.truncate_start = truncate_start;
110+ self
111+ }
112+
103113 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
104114 self.picker
105115 .selection()
@@ -176,7 +186,6 @@ impl<T: 'static> Component for FilePicker<T> {
176186 };
177187
178188 let picker_area = area.with_width(picker_width);
179− self.picker.truncate_start = self.truncate_start;
180189 self.picker.render(picker_area, surface, cx);
181190
182191 if !render_preview {