Skip to content
Open
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
2 changes: 1 addition & 1 deletion helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ impl Component for Prompt {
// store in history
if let Some(register) = self.history_register {
if let Err(err) =
cx.editor.registers.push(register, self.line.clone())
cx.editor.registers.push_unique(register, self.line.clone())
{
cx.editor.set_error(err.to_string());
}
Expand Down
19 changes: 17 additions & 2 deletions helix-view/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Registers {
}
}

pub fn push(&mut self, name: char, mut value: String) -> Result<()> {
fn push_impl(&mut self, name: char, mut value: String, unique: bool) -> Result<()> {
match name {
'_' => Ok(()),
'#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support pushing")),
Expand All @@ -122,6 +122,9 @@ impl Registers {
anyhow::bail!("Failed to push to register {name}: clipboard does not match register contents");
}

if unique {
saved_values.retain(|the| the != &value);
}
saved_values.push(value.clone());
if !contents.is_empty() {
value.push_str(NATIVE_LINE_ENDING.as_str());
Expand All @@ -134,12 +137,24 @@ impl Registers {
Ok(())
}
_ => {
self.inner.entry(name).or_default().push(value);
let the = self.inner.entry(name).or_default();
if unique {
the.retain(|the| the != &value);
}
the.push(value);
Ok(())
}
}
}

pub fn push_unique(&mut self, name: char, value: String) -> Result<()> {
self.push_impl(name, value, true)
}

pub fn push(&mut self, name: char, value: String) -> Result<()> {
self.push_impl(name, value, false)
}

pub fn first<'a>(&'a self, name: char, editor: &'a Editor) -> Option<Cow<'a, str>> {
self.read(name, editor).and_then(|mut values| values.next())
}
Expand Down