Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global_search: Save search when accepting an option #11209

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
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);
Expand Down
19 changes: 11 additions & 8 deletions helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,16 @@ impl Prompt {
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 {
Expand Down Expand Up @@ -603,14 +613,7 @@ impl Component for Prompt {
&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
Expand Down
Loading