aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorWojciech Kępka2021-06-07 18:13:40 +0000
committerBlaž Hrastnik2021-06-08 00:50:14 +0000
commitc65b4dea099abc7512720e8407b53a3742083039 (patch)
tree79aad34860b70731ea23fe11c53b923da98ffc36 /helix-term
parent6fc0e0b5fbe29e1b3ace2d1a0abc5a5b3d8380f8 (diff)
commands: Add replace with yanked as `R`
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs20
-rw-r--r--helix-term/src/keymap.rs1
2 files changed, 21 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 0c33241f..0da23fc7 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1948,6 +1948,26 @@ fn _paste(reg: char, doc: &mut Document, view: &View, action: Paste) -> Option<T
None
}
+pub fn replace_with_yanked(cx: &mut Context) {
+ let reg = cx.register.name();
+
+ if let Some(values) = register::get(reg) {
+ let (view, doc) = cx.current();
+
+ if let Some(yank) = values.first() {
+ let transaction =
+ Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
+ let max_to = doc.text().len_chars().saturating_sub(1);
+ let to = std::cmp::min(max_to, range.to());
+ (range.from(), to, Some(yank.as_str().into()))
+ });
+
+ doc.apply(&transaction, view.id);
+ doc.append_changes_to_history(view.id);
+ }
+ }
+}
+
// alt-p => paste every yanked selection after selected text
// alt-P => paste every yanked selection before selected text
// R => replace selected text with yanked text
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index d2fa46c7..0324fd04 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -156,6 +156,7 @@ pub fn default() -> Keymaps {
// and matching set for select mode (extend)
//
key!('r') => commands::replace,
+ key!('R') => commands::replace_with_yanked,
KeyEvent {
code: KeyCode::Home,