aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs10
-rw-r--r--helix-term/src/ui/prompt.rs20
2 files changed, 12 insertions, 18 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 5498a437..e5ca5611 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1805,7 +1805,7 @@ fn search_selection(cx: &mut Context) {
.join("|");
let msg = format!("register '{}' set to '{}'", '/', &regex);
- cx.editor.registers.get_mut('/').push(regex);
+ cx.editor.registers.push('/', regex);
cx.editor.set_status(msg);
}
@@ -2121,16 +2121,14 @@ enum Operation {
fn delete_selection_impl(cx: &mut Context, op: Operation) {
let (view, doc) = current!(cx.editor);
- let text = doc.text().slice(..);
let selection = doc.selection(view.id);
if cx.register != Some('_') {
// first yank the selection
+ let text = doc.text().slice(..);
let values: Vec<String> = selection.fragments(text).map(Cow::into_owned).collect();
let reg_name = cx.register.unwrap_or('"');
- let registers = &mut cx.editor.registers;
- let reg = registers.get_mut(reg_name);
- reg.write(values);
+ cx.editor.registers.write(reg_name, values);
};
// then delete
@@ -5005,7 +5003,7 @@ fn record_macro(cx: &mut Context) {
}
})
.collect::<String>();
- cx.editor.registers.get_mut(reg).write(vec![s]);
+ cx.editor.registers.write(reg, vec![s]);
cx.editor
.set_status(format!("Recorded to register [{}]", reg));
} else {
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs
index 51ef688d..b19b9a9f 100644
--- a/helix-term/src/ui/prompt.rs
+++ b/helix-term/src/ui/prompt.rs
@@ -294,23 +294,22 @@ impl Prompt {
direction: CompletionDirection,
) {
(self.callback_fn)(cx, &self.line, PromptEvent::Abort);
- let register = cx.editor.registers.get_mut(register).read();
-
- if register.is_empty() {
- return;
- }
+ let values = match cx.editor.registers.read(register) {
+ Some(values) if !values.is_empty() => values,
+ _ => return,
+ };
- let end = register.len().saturating_sub(1);
+ let end = values.len().saturating_sub(1);
let index = match direction {
CompletionDirection::Forward => self.history_pos.map_or(0, |i| i + 1),
CompletionDirection::Backward => {
- self.history_pos.unwrap_or(register.len()).saturating_sub(1)
+ self.history_pos.unwrap_or(values.len()).saturating_sub(1)
}
}
.min(end);
- self.line = register[index].clone();
+ self.line = values[index].clone();
self.history_pos = Some(index);
@@ -548,10 +547,7 @@ impl Component for Prompt {
if last_item != self.line {
// store in history
if let Some(register) = self.history_register {
- cx.editor
- .registers
- .get_mut(register)
- .push(self.line.clone());
+ cx.editor.registers.push(register, self.line.clone());
};
}