diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 480db369d..6d0f26c41 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -530,6 +530,31 @@ impl Picker { EventResult::Consumed(None) } + fn save_search(&mut self, ctx: &mut Context) { + if self.is_history_search { + return; + } + if let Some(history_register) = self.prompt.history_register() { + let query = self.primary_query(); + + let should_push = ctx + .editor + .registers + .first(history_register, &ctx.editor) + .map_or(true, |first| *first != *query); + + if should_push { + if let Err(err) = ctx + .editor + .registers + .push(history_register, query.to_string()) + { + ctx.editor.set_error(err.to_string()); + } + } + } + } + fn handle_prompt_change(&mut self, is_paste: bool) { // TODO: better track how the pattern has changed let line = self.prompt.line(); @@ -1094,6 +1119,7 @@ impl Component for Picker { // If the prompt has a history completion and is empty, use enter to accept @@ -1112,17 +1138,7 @@ impl Component for Picker Component for Picker { if let Some(option) = self.selection() { (self.callback_fn)(ctx, option, Action::VerticalSplit); } + self.save_search(ctx); return close_fn(self); } ctrl!('t') => {