aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands/typed.rs
diff options
context:
space:
mode:
authorMichael Davis2023-07-11 15:23:49 +0000
committerBlaž Hrastnik2023-07-31 06:05:38 +0000
commit4555a6b4332b48384d4bccfef527d26060c34037 (patch)
treebaab80c83c6e4abe9bf9035794045d6ba575bb1f /helix-term/src/commands/typed.rs
parent2d838d729cca26a718e3536e8d75c60396420dbd (diff)
Reimplement clipboard commands in terms of special regs
Since the clipboard provider now lives on the Registers type, we want to eliminate it from the Editor. We can do that and clean up the commands that interact with the clipboard by calling regular yank, paste and replace impls on the clipboard special registers. Eventually the clipboard commands could be removed once macro keybinding is supported.
Diffstat (limited to 'helix-term/src/commands/typed.rs')
-rw-r--r--helix-term/src/commands/typed.rs55
1 files changed, 21 insertions, 34 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 28759b3f..67640f79 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -904,7 +904,8 @@ fn yank_main_selection_to_clipboard(
return Ok(());
}
- yank_main_selection_to_clipboard_impl(cx.editor, ClipboardType::Clipboard)
+ yank_primary_selection_impl(cx.editor, '*');
+ Ok(())
}
fn yank_joined(
@@ -938,7 +939,8 @@ fn yank_joined_to_clipboard(
let doc = doc!(cx.editor);
let default_sep = Cow::Borrowed(doc.line_ending.as_str());
let separator = args.first().unwrap_or(&default_sep);
- yank_joined_to_clipboard_impl(cx.editor, separator, ClipboardType::Clipboard)
+ yank_joined_impl(cx.editor, separator, '*');
+ Ok(())
}
fn yank_main_selection_to_primary_clipboard(
@@ -950,7 +952,8 @@ fn yank_main_selection_to_primary_clipboard(
return Ok(());
}
- yank_main_selection_to_clipboard_impl(cx.editor, ClipboardType::Selection)
+ yank_primary_selection_impl(cx.editor, '+');
+ Ok(())
}
fn yank_joined_to_primary_clipboard(
@@ -965,7 +968,8 @@ fn yank_joined_to_primary_clipboard(
let doc = doc!(cx.editor);
let default_sep = Cow::Borrowed(doc.line_ending.as_str());
let separator = args.first().unwrap_or(&default_sep);
- yank_joined_to_clipboard_impl(cx.editor, separator, ClipboardType::Selection)
+ yank_joined_impl(cx.editor, separator, '+');
+ Ok(())
}
fn paste_clipboard_after(
@@ -977,7 +981,8 @@ fn paste_clipboard_after(
return Ok(());
}
- paste_clipboard_impl(cx.editor, Paste::After, ClipboardType::Clipboard, 1)
+ paste(cx.editor, '*', Paste::After, 1);
+ Ok(())
}
fn paste_clipboard_before(
@@ -989,7 +994,8 @@ fn paste_clipboard_before(
return Ok(());
}
- paste_clipboard_impl(cx.editor, Paste::Before, ClipboardType::Clipboard, 1)
+ paste(cx.editor, '*', Paste::Before, 1);
+ Ok(())
}
fn paste_primary_clipboard_after(
@@ -1001,7 +1007,8 @@ fn paste_primary_clipboard_after(
return Ok(());
}
- paste_clipboard_impl(cx.editor, Paste::After, ClipboardType::Selection, 1)
+ paste(cx.editor, '+', Paste::After, 1);
+ Ok(())
}
fn paste_primary_clipboard_before(
@@ -1013,30 +1020,8 @@ fn paste_primary_clipboard_before(
return Ok(());
}
- paste_clipboard_impl(cx.editor, Paste::Before, ClipboardType::Selection, 1)
-}
-
-fn replace_selections_with_clipboard_impl(
- cx: &mut compositor::Context,
- clipboard_type: ClipboardType,
-) -> anyhow::Result<()> {
- let scrolloff = cx.editor.config().scrolloff;
- let (view, doc) = current!(cx.editor);
-
- match cx.editor.clipboard_provider.get_contents(clipboard_type) {
- Ok(contents) => {
- let selection = doc.selection(view.id);
- let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
- (range.from(), range.to(), Some(contents.as_str().into()))
- });
-
- doc.apply(&transaction, view.id);
- doc.append_changes_to_history(view);
- view.ensure_cursor_in_view(doc, scrolloff);
- Ok(())
- }
- Err(e) => Err(e.context("Couldn't get system clipboard contents")),
- }
+ paste(cx.editor, '+', Paste::Before, 1);
+ Ok(())
}
fn replace_selections_with_clipboard(
@@ -1048,7 +1033,8 @@ fn replace_selections_with_clipboard(
return Ok(());
}
- replace_selections_with_clipboard_impl(cx, ClipboardType::Clipboard)
+ replace_with_yanked_impl(cx.editor, '*', 1);
+ Ok(())
}
fn replace_selections_with_primary_clipboard(
@@ -1060,7 +1046,8 @@ fn replace_selections_with_primary_clipboard(
return Ok(());
}
- replace_selections_with_clipboard_impl(cx, ClipboardType::Selection)
+ replace_with_yanked_impl(cx.editor, '+', 1);
+ Ok(())
}
fn show_clipboard_provider(
@@ -1073,7 +1060,7 @@ fn show_clipboard_provider(
}
cx.editor
- .set_status(cx.editor.clipboard_provider.name().to_string());
+ .set_status(cx.editor.registers.clipboard_provider_name().to_string());
Ok(())
}