mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 17:36:19 +04:00
Accept 'IntoIterator<Item = T>' for Picker::new options
`Picker::new` loops through the input options to inject each of them, so there's no need to collect into an intermediary Vec. This removes some unnecessary collections. Also, pickers that start with no initial options can now pass an empty slice instead of an empty Vec. Co-authored-by: Luis Useche <useche@gmail.com>
This commit is contained in:
parent
3906f6605f
commit
8555248b01
@ -2404,7 +2404,7 @@ struct GlobalSearchConfig {
|
|||||||
let picker = Picker::new(
|
let picker = Picker::new(
|
||||||
columns,
|
columns,
|
||||||
1, // contents
|
1, // contents
|
||||||
vec![],
|
[],
|
||||||
config,
|
config,
|
||||||
move |cx, FileResult { path, line_num, .. }, action| {
|
move |cx, FileResult { path, line_num, .. }, action| {
|
||||||
let doc = match cx.editor.open(path, action) {
|
let doc = match cx.editor.open(path, action) {
|
||||||
@ -2991,16 +2991,12 @@ struct JumpMeta {
|
|||||||
let picker = Picker::new(
|
let picker = Picker::new(
|
||||||
columns,
|
columns,
|
||||||
1, // path
|
1, // path
|
||||||
cx.editor
|
cx.editor.tree.views().flat_map(|(view, _)| {
|
||||||
.tree
|
|
||||||
.views()
|
|
||||||
.flat_map(|(view, _)| {
|
|
||||||
view.jumps
|
view.jumps
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.map(|(doc_id, selection)| new_meta(view, *doc_id, selection.clone()))
|
.map(|(doc_id, selection)| new_meta(view, *doc_id, selection.clone()))
|
||||||
})
|
}),
|
||||||
.collect(),
|
|
||||||
(),
|
(),
|
||||||
|cx, meta, action| {
|
|cx, meta, action| {
|
||||||
cx.editor.switch(meta.id, action);
|
cx.editor.switch(meta.id, action);
|
||||||
@ -3077,7 +3073,7 @@ pub struct FileChangeData {
|
|||||||
let picker = Picker::new(
|
let picker = Picker::new(
|
||||||
columns,
|
columns,
|
||||||
1, // path
|
1, // path
|
||||||
Vec::new(),
|
[],
|
||||||
FileChangeData {
|
FileChangeData {
|
||||||
cwd: cwd.clone(),
|
cwd: cwd.clone(),
|
||||||
style_untracked: added,
|
style_untracked: added,
|
||||||
@ -3124,14 +3120,15 @@ pub fn command_palette(cx: &mut Context) {
|
|||||||
[&cx.editor.mode]
|
[&cx.editor.mode]
|
||||||
.reverse_map();
|
.reverse_map();
|
||||||
|
|
||||||
let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into();
|
let commands = MappableCommand::STATIC_COMMAND_LIST.iter().cloned().chain(
|
||||||
commands.extend(typed::TYPABLE_COMMAND_LIST.iter().map(|cmd| {
|
typed::TYPABLE_COMMAND_LIST
|
||||||
MappableCommand::Typable {
|
.iter()
|
||||||
|
.map(|cmd| MappableCommand::Typable {
|
||||||
name: cmd.name.to_owned(),
|
name: cmd.name.to_owned(),
|
||||||
doc: cmd.doc.to_owned(),
|
|
||||||
args: Vec::new(),
|
args: Vec::new(),
|
||||||
}
|
doc: cmd.doc.to_owned(),
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
let columns = vec![
|
let columns = vec![
|
||||||
ui::PickerColumn::new("name", |item, _| match item {
|
ui::PickerColumn::new("name", |item, _| match item {
|
||||||
|
@ -501,7 +501,7 @@ pub fn workspace_symbol_picker(cx: &mut Context) {
|
|||||||
let picker = Picker::new(
|
let picker = Picker::new(
|
||||||
columns,
|
columns,
|
||||||
1, // name column
|
1, // name column
|
||||||
vec![],
|
[],
|
||||||
(),
|
(),
|
||||||
move |cx, item, action| {
|
move |cx, item, action| {
|
||||||
jump_to_location(
|
jump_to_location(
|
||||||
|
@ -228,12 +228,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
|
|||||||
.into()
|
.into()
|
||||||
},
|
},
|
||||||
)];
|
)];
|
||||||
let picker = Picker::new(
|
let picker = Picker::new(columns, 0, [], root, move |cx, path: &PathBuf, action| {
|
||||||
columns,
|
|
||||||
0,
|
|
||||||
Vec::new(),
|
|
||||||
root,
|
|
||||||
move |cx, path: &PathBuf, action| {
|
|
||||||
if let Err(e) = cx.editor.open(path, action) {
|
if let Err(e) = cx.editor.open(path, action) {
|
||||||
let err = if let Some(err) = e.source() {
|
let err = if let Some(err) = e.source() {
|
||||||
format!("{}", err)
|
format!("{}", err)
|
||||||
@ -242,8 +237,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
|
|||||||
};
|
};
|
||||||
cx.editor.set_error(err);
|
cx.editor.set_error(err);
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
)
|
|
||||||
.with_preview(|_editor, path| Some((path.as_path().into(), None)));
|
.with_preview(|_editor, path| Some((path.as_path().into(), None)));
|
||||||
let injector = picker.injector();
|
let injector = picker.injector();
|
||||||
let timeout = std::time::Instant::now() + std::time::Duration::from_millis(30);
|
let timeout = std::time::Instant::now() + std::time::Duration::from_millis(30);
|
||||||
|
@ -298,7 +298,7 @@ pub fn stream(columns: Vec<Column<T, D>>, editor_data: D) -> (Nucleo<T>, Injecto
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
columns: Vec<Column<T, D>>,
|
columns: Vec<Column<T, D>>,
|
||||||
primary_column: usize,
|
primary_column: usize,
|
||||||
options: Vec<T>,
|
options: impl IntoIterator<Item = T>,
|
||||||
editor_data: D,
|
editor_data: D,
|
||||||
callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
|
callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user