Skip to content

Commit

Permalink
Moved truncation of the symbol pickers to the end.
Browse files Browse the repository at this point in the history
  • Loading branch information
EbbDrop committed Nov 11, 2021
1 parent 70ed999 commit 32aa748
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2685,7 +2685,7 @@ fn symbol_picker(cx: &mut Context) {
}
};

let picker = FilePicker::new(
let mut picker = FilePicker::new(
symbols,
|symbol| (&symbol.name).into(),
move |editor: &mut Editor, symbol, _action| {
Expand All @@ -2710,6 +2710,7 @@ fn symbol_picker(cx: &mut Context) {
Some((path, line))
},
);
picker.truncate_start = false;
compositor.push(Box::new(picker))
}
},
Expand All @@ -2734,7 +2735,7 @@ fn workspace_symbol_picker(cx: &mut Context) {
compositor: &mut Compositor,
response: Option<Vec<lsp::SymbolInformation>>| {
if let Some(symbols) = response {
let picker = FilePicker::new(
let mut picker = FilePicker::new(
symbols,
move |symbol| {
let path = symbol.location.uri.to_file_path().unwrap();
Expand Down Expand Up @@ -2771,6 +2772,7 @@ fn workspace_symbol_picker(cx: &mut Context) {
Some((path, line))
},
);
picker.truncate_start = false;
compositor.push(Box::new(picker))
}
},
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl Default for Keymaps {
"f" => file_picker,
"b" => buffer_picker,
"s" => symbol_picker,
"t" => workspace_symbol_picker,
"S" => workspace_symbol_picker,
"a" => code_action,
"'" => last_picker,
"w" => { "Window"
Expand Down
8 changes: 7 additions & 1 deletion helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type FileLocation = (PathBuf, Option<(usize, usize)>);

pub struct FilePicker<T> {
picker: Picker<T>,
pub truncate_start: bool,
/// Caches paths to documents
preview_cache: HashMap<PathBuf, CachedPreview>,
read_buffer: Vec<u8>,
Expand Down Expand Up @@ -89,6 +90,7 @@ impl<T> FilePicker<T> {
) -> Self {
Self {
picker: Picker::new(false, options, format_fn, callback_fn),
truncate_start: true,
preview_cache: HashMap::new(),
read_buffer: Vec::with_capacity(1024),
file_fn: Box::new(preview_fn),
Expand Down Expand Up @@ -171,6 +173,7 @@ impl<T: 'static> Component for FilePicker<T> {
};

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 {
Expand Down Expand Up @@ -276,6 +279,8 @@ pub struct Picker<T> {
prompt: Prompt,
/// Whether to render in the middle of the area
render_centered: bool,
/// Wheather to truncate the start (default true)
pub truncate_start: bool,

format_fn: Box<dyn Fn(&T) -> Cow<str>>,
callback_fn: Box<dyn Fn(&mut Editor, &T, Action)>,
Expand Down Expand Up @@ -305,6 +310,7 @@ impl<T> Picker<T> {
cursor: 0,
prompt,
render_centered,
truncate_start: true,
format_fn: Box::new(format_fn),
callback_fn: Box::new(callback_fn),
};
Expand Down Expand Up @@ -566,7 +572,7 @@ impl<T: 'static> Component for Picker<T> {
text_style
},
true,
true,
self.truncate_start,
);
}
}
Expand Down

0 comments on commit 32aa748

Please sign in to comment.