on master help sign in
Make truncate_start a builder method instead
4940db3Blaž Hrastnik
helix-term/src/commands/lsp.rs+3−3
@@ -71,7 +71,7 @@ fn sym_picker(
71) -> FilePicker<lsp::SymbolInformation> {
71) -> FilePicker<lsp::SymbolInformation> {
72 // TODO: drop current_path comparison and instead use workspace: bool flag?
72 // TODO: drop current_path comparison and instead use workspace: bool flag?
73 let current_path2 = current_path.clone();
73 let current_path2 = current_path.clone();
74− let mut picker = FilePicker::new(
74+ let picker = FilePicker::new(
75 symbols,
75 symbols,
76 move |symbol| {
76 move |symbol| {
77 if current_path.as_ref() == Some(&symbol.location.uri) {
77 if current_path.as_ref() == Some(&symbol.location.uri) {
@@ -104,8 +104,8 @@ fn sym_picker(
104 }
104 }
105 },
105 },
106 move |_editor, symbol| Some(location_to_file_location(&symbol.location)),
106 move |_editor, symbol| Some(location_to_file_location(&symbol.location)),
107− );
107+ )
108− picker.truncate_start = false;
108+ .truncate_start(false);
109 picker
109 picker
110}
110}
111
111
helix-term/src/ui/picker.rs+12−3
@@ -91,15 +91,25 @@ impl<T> FilePicker<T> {
91 callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
91 callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
92 preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static,
92 preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static,
93 ) -> Self {
93 ) -> Self {
94+ let truncate_start = true;
95+ let mut picker = Picker::new(options, format_fn, callback_fn);
96+ picker.truncate_start = truncate_start;
97+
94 Self {
98 Self {
95− picker: Picker::new(options, format_fn, callback_fn),
99+ picker,
96− truncate_start: true,
100+ truncate_start,
97 preview_cache: HashMap::new(),
101 preview_cache: HashMap::new(),
98 read_buffer: Vec::with_capacity(1024),
102 read_buffer: Vec::with_capacity(1024),
99 file_fn: Box::new(preview_fn),
103 file_fn: Box::new(preview_fn),
100 }
104 }
101 }
105 }
102
106
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+
103 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
113 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
104 self.picker
114 self.picker
105 .selection()
115 .selection()
@@ -176,7 +186,6 @@ impl<T: 'static> Component for FilePicker<T> {
176 };
186 };
177
187
178 let picker_area = area.with_width(picker_width);
188 let picker_area = area.with_width(picker_width);
179− self.picker.truncate_start = self.truncate_start;
180 self.picker.render(picker_area, surface, cx);
189 self.picker.render(picker_area, surface, cx);
181
190
182 if !render_preview {
191 if !render_preview {