mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
global_search: Save search when accepting an option (#11209)
The Prompt is set up to push the current line to history when hitting Enter but the Picker doesn't pass the Enter event down to the Prompt (for good reason: we don't want the Prompt's behavior of changing completions when we hit a path separator). We should save the Prompt's line to its configured history register when hitting Enter when there is a selection in the Picker. This currently only applies to `global_search`'s Picker since it's the only Picker to use `Picker::with_history_register`.
This commit is contained in:
parent
bd5e893149
commit
c9d829a26d
@ -1031,6 +1031,7 @@ fn handle_event(&mut self, event: &Event, ctx: &mut Context) -> EventResult {
|
||||
self.handle_prompt_change();
|
||||
} else {
|
||||
if let Some(option) = self.selection() {
|
||||
self.prompt.save_line_to_history(ctx.editor);
|
||||
(self.callback_fn)(ctx, option, Action::Replace);
|
||||
}
|
||||
return close_fn(self);
|
||||
|
@ -516,6 +516,16 @@ pub fn render_prompt(&self, area: Rect, surface: &mut Surface, cx: &mut Context)
|
||||
surface.set_string(line_area.x, line_area.y, self.line.clone(), prompt_color);
|
||||
}
|
||||
}
|
||||
|
||||
/// Saves the current line to the configured history register, if there is one.
|
||||
pub(crate) fn save_line_to_history(&self, editor: &mut Editor) {
|
||||
let Some(register) = self.history_register else {
|
||||
return;
|
||||
};
|
||||
if let Err(err) = editor.registers.push(register, self.line.clone()) {
|
||||
editor.set_error(err.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for Prompt {
|
||||
@ -603,14 +613,7 @@ fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
|
||||
&last_item
|
||||
} else {
|
||||
if last_item != self.line {
|
||||
// store in history
|
||||
if let Some(register) = self.history_register {
|
||||
if let Err(err) =
|
||||
cx.editor.registers.push(register, self.line.clone())
|
||||
{
|
||||
cx.editor.set_error(err.to_string());
|
||||
}
|
||||
};
|
||||
self.save_line_to_history(cx.editor);
|
||||
}
|
||||
|
||||
&self.line
|
||||
|
Loading…
Reference in New Issue
Block a user