mirror of https://github.com/helix-editor/helix
Save to history on C-v/C-s/Alt-Enter
parent
37c3b26a37
commit
639dba4111
|
@ -530,6 +530,31 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
|
||||||
EventResult::Consumed(None)
|
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) {
|
fn handle_prompt_change(&mut self, is_paste: bool) {
|
||||||
// TODO: better track how the pattern has changed
|
// TODO: better track how the pattern has changed
|
||||||
let line = self.prompt.line();
|
let line = self.prompt.line();
|
||||||
|
@ -1094,6 +1119,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(ctx, option, Action::Replace);
|
(self.callback_fn)(ctx, option, Action::Replace);
|
||||||
}
|
}
|
||||||
|
self.save_search(ctx);
|
||||||
}
|
}
|
||||||
key!(Enter) => {
|
key!(Enter) => {
|
||||||
// If the prompt has a history completion and is empty, use enter to accept
|
// If the prompt has a history completion and is empty, use enter to accept
|
||||||
|
@ -1112,17 +1138,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(ctx, option, Action::Replace);
|
(self.callback_fn)(ctx, option, Action::Replace);
|
||||||
}
|
}
|
||||||
if !self.is_history_search {
|
self.save_search(ctx);
|
||||||
if let Some(history_register) = self.prompt.history_register() {
|
|
||||||
if let Err(err) = ctx
|
|
||||||
.editor
|
|
||||||
.registers
|
|
||||||
.push(history_register, self.primary_query().to_string())
|
|
||||||
{
|
|
||||||
ctx.editor.set_error(err.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return close_fn(self);
|
return close_fn(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1130,12 +1146,14 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(ctx, option, Action::HorizontalSplit);
|
(self.callback_fn)(ctx, option, Action::HorizontalSplit);
|
||||||
}
|
}
|
||||||
|
self.save_search(ctx);
|
||||||
return close_fn(self);
|
return close_fn(self);
|
||||||
}
|
}
|
||||||
ctrl!('v') => {
|
ctrl!('v') => {
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(ctx, option, Action::VerticalSplit);
|
(self.callback_fn)(ctx, option, Action::VerticalSplit);
|
||||||
}
|
}
|
||||||
|
self.save_search(ctx);
|
||||||
return close_fn(self);
|
return close_fn(self);
|
||||||
}
|
}
|
||||||
ctrl!('t') => {
|
ctrl!('t') => {
|
||||||
|
|
Loading…
Reference in New Issue