mirror of https://github.com/helix-editor/helix
add command history picker
parent
22a051408a
commit
c485063e78
|
@ -282,6 +282,7 @@ This layer is a kludge of mappings, mostly pickers.
|
||||||
| `F` | Open file picker at current working directory | `file_picker_in_current_directory` |
|
| `F` | Open file picker at current working directory | `file_picker_in_current_directory` |
|
||||||
| `b` | Open buffer picker | `buffer_picker` |
|
| `b` | Open buffer picker | `buffer_picker` |
|
||||||
| `j` | Open jumplist picker | `jumplist_picker` |
|
| `j` | Open jumplist picker | `jumplist_picker` |
|
||||||
|
| `:` | Open command history picker | `command_history_picker` |
|
||||||
| `g` | Open changed file picker | `changed_file_picker` |
|
| `g` | Open changed file picker | `changed_file_picker` |
|
||||||
| `G` | Debug (experimental) | N/A |
|
| `G` | Debug (experimental) | N/A |
|
||||||
| `k` | Show documentation for item under cursor in a [popup](#popup) (**LSP**) | `hover` |
|
| `k` | Show documentation for item under cursor in a [popup](#popup) (**LSP**) | `hover` |
|
||||||
|
|
|
@ -340,6 +340,7 @@ impl MappableCommand {
|
||||||
code_action, "Perform code action",
|
code_action, "Perform code action",
|
||||||
buffer_picker, "Open buffer picker",
|
buffer_picker, "Open buffer picker",
|
||||||
jumplist_picker, "Open jumplist picker",
|
jumplist_picker, "Open jumplist picker",
|
||||||
|
command_history_picker, "Open command history picker",
|
||||||
symbol_picker, "Open symbol picker",
|
symbol_picker, "Open symbol picker",
|
||||||
changed_file_picker, "Open changed file picker",
|
changed_file_picker, "Open changed file picker",
|
||||||
select_references_to_symbol_under_cursor, "Select symbol references",
|
select_references_to_symbol_under_cursor, "Select symbol references",
|
||||||
|
@ -2926,6 +2927,42 @@ fn buffer_picker(cx: &mut Context) {
|
||||||
cx.push_layer(Box::new(overlaid(picker)));
|
cx.push_layer(Box::new(overlaid(picker)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn command_history_picker(cx: &mut Context) {
|
||||||
|
let command_history = cx.editor.registers.read(':', cx.editor);
|
||||||
|
|
||||||
|
let items: Vec<Command> = command_history
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.map(|entry| Command {
|
||||||
|
args: entry.to_string(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
struct Command {
|
||||||
|
args: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
let columns = [PickerColumn::new("command", |command: &Command, _| {
|
||||||
|
format!(":{}", command.args).into()
|
||||||
|
})];
|
||||||
|
|
||||||
|
let picker = Picker::new(columns, 0, items, (), |cx, option, _action| {
|
||||||
|
let args = option.args.clone();
|
||||||
|
|
||||||
|
cx.jobs.callback(async move {
|
||||||
|
let callback = |editor: &mut Editor, compositor: &mut Compositor| {
|
||||||
|
let prompt = command_mode_prompt().with_line(args, editor);
|
||||||
|
|
||||||
|
compositor.push(Box::new(prompt));
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Callback::EditorCompositor(Box::new(callback)))
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.push_layer(Box::new(overlaid(picker)));
|
||||||
|
}
|
||||||
|
|
||||||
fn jumplist_picker(cx: &mut Context) {
|
fn jumplist_picker(cx: &mut Context) {
|
||||||
struct JumpMeta {
|
struct JumpMeta {
|
||||||
id: DocumentId,
|
id: DocumentId,
|
||||||
|
|
|
@ -3156,6 +3156,14 @@ pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableComma
|
||||||
|
|
||||||
#[allow(clippy::unnecessary_unwrap)]
|
#[allow(clippy::unnecessary_unwrap)]
|
||||||
pub(super) fn command_mode(cx: &mut Context) {
|
pub(super) fn command_mode(cx: &mut Context) {
|
||||||
|
let mut prompt = command_mode_prompt();
|
||||||
|
|
||||||
|
// Calculate initial completion
|
||||||
|
prompt.recalculate_completion(cx.editor);
|
||||||
|
cx.push_layer(Box::new(prompt));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn command_mode_prompt() -> Prompt {
|
||||||
let mut prompt = Prompt::new(
|
let mut prompt = Prompt::new(
|
||||||
":".into(),
|
":".into(),
|
||||||
Some(':'),
|
Some(':'),
|
||||||
|
@ -3246,9 +3254,7 @@ pub(super) fn command_mode(cx: &mut Context) {
|
||||||
None
|
None
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calculate initial completion
|
prompt
|
||||||
prompt.recalculate_completion(cx.editor);
|
|
||||||
cx.push_layer(Box::new(prompt));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn argument_number_of(shellwords: &Shellwords) -> usize {
|
fn argument_number_of(shellwords: &Shellwords) -> usize {
|
||||||
|
|
|
@ -223,6 +223,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
|
||||||
"F" => file_picker_in_current_directory,
|
"F" => file_picker_in_current_directory,
|
||||||
"b" => buffer_picker,
|
"b" => buffer_picker,
|
||||||
"j" => jumplist_picker,
|
"j" => jumplist_picker,
|
||||||
|
":" => command_history_picker,
|
||||||
"s" => symbol_picker,
|
"s" => symbol_picker,
|
||||||
"S" => workspace_symbol_picker,
|
"S" => workspace_symbol_picker,
|
||||||
"d" => diagnostics_picker,
|
"d" => diagnostics_picker,
|
||||||
|
|
Loading…
Reference in New Issue