support toggling pickers' preview panel (#3021)
* support toggling pickers' preview panel * add doc for toggling preview
This commit is contained in:
parent
dbf68e0370
commit
2a8d38c27b
2 changed files with 12 additions and 1 deletions
|
@ -352,6 +352,7 @@ Keys to use within picker. Remapping currently not supported.
|
||||||
| `Enter` | Open selected |
|
| `Enter` | Open selected |
|
||||||
| `Ctrl-s` | Open horizontally |
|
| `Ctrl-s` | Open horizontally |
|
||||||
| `Ctrl-v` | Open vertically |
|
| `Ctrl-v` | Open vertically |
|
||||||
|
| `Ctrl-t` | Toggle preview |
|
||||||
| `Escape`, `Ctrl-c` | Close picker |
|
| `Escape`, `Ctrl-c` | Close picker |
|
||||||
|
|
||||||
# Prompt
|
# Prompt
|
||||||
|
|
|
@ -173,7 +173,7 @@ impl<T: Item + 'static> Component for FilePicker<T> {
|
||||||
// | | | |
|
// | | | |
|
||||||
// +---------+ +---------+
|
// +---------+ +---------+
|
||||||
|
|
||||||
let render_preview = area.width > MIN_AREA_WIDTH_FOR_PREVIEW;
|
let render_preview = self.picker.show_preview && area.width > MIN_AREA_WIDTH_FOR_PREVIEW;
|
||||||
// -- Render the frame:
|
// -- Render the frame:
|
||||||
// clear area
|
// clear area
|
||||||
let background = cx.editor.theme.get("ui.background");
|
let background = cx.editor.theme.get("ui.background");
|
||||||
|
@ -300,6 +300,8 @@ pub struct Picker<T: Item> {
|
||||||
previous_pattern: String,
|
previous_pattern: String,
|
||||||
/// Whether to truncate the start (default true)
|
/// Whether to truncate the start (default true)
|
||||||
pub truncate_start: bool,
|
pub truncate_start: bool,
|
||||||
|
/// Whether to show the preview panel (default true)
|
||||||
|
show_preview: bool,
|
||||||
|
|
||||||
callback_fn: Box<dyn Fn(&mut Context, &T, Action)>,
|
callback_fn: Box<dyn Fn(&mut Context, &T, Action)>,
|
||||||
}
|
}
|
||||||
|
@ -327,6 +329,7 @@ impl<T: Item> Picker<T> {
|
||||||
prompt,
|
prompt,
|
||||||
previous_pattern: String::new(),
|
previous_pattern: String::new(),
|
||||||
truncate_start: true,
|
truncate_start: true,
|
||||||
|
show_preview: true,
|
||||||
callback_fn: Box::new(callback_fn),
|
callback_fn: Box::new(callback_fn),
|
||||||
completion_height: 0,
|
completion_height: 0,
|
||||||
};
|
};
|
||||||
|
@ -470,6 +473,10 @@ impl<T: Item> Picker<T> {
|
||||||
self.filters.sort_unstable(); // used for binary search later
|
self.filters.sort_unstable(); // used for binary search later
|
||||||
self.prompt.clear(cx);
|
self.prompt.clear(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn toggle_preview(&mut self) {
|
||||||
|
self.show_preview = !self.show_preview;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// process:
|
// process:
|
||||||
|
@ -538,6 +545,9 @@ impl<T: Item + 'static> Component for Picker<T> {
|
||||||
ctrl!(' ') => {
|
ctrl!(' ') => {
|
||||||
self.save_filter(cx);
|
self.save_filter(cx);
|
||||||
}
|
}
|
||||||
|
ctrl!('t') => {
|
||||||
|
self.toggle_preview();
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) {
|
if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) {
|
||||||
// TODO: recalculate only if pattern changed
|
// TODO: recalculate only if pattern changed
|
||||||
|
|
Loading…
Add table
Reference in a new issue