Unnamed repository; edit this file 'description' to name the repository.
Add support for configuring clipboard used for mouse yank (#11414)
Co-authored-by: Daniel Åkerud <[email protected]>
Mathis Brossier 4 months ago
parent f9335f6 · commit 6b2dccf
-rw-r--r--book/src/editor.md3
-rw-r--r--helix-term/src/commands.rs21
-rw-r--r--helix-term/src/commands/typed.rs8
-rw-r--r--helix-term/src/ui/editor.rs21
-rw-r--r--helix-view/src/editor.rs3
5 files changed, 35 insertions, 21 deletions
diff --git a/book/src/editor.md b/book/src/editor.md
index 3c05965a..0e65ed22 100644
--- a/book/src/editor.md
+++ b/book/src/editor.md
@@ -29,8 +29,9 @@
|--|--|---------|
| `scrolloff` | Number of lines of padding around the edge of the screen when scrolling | `5` |
| `mouse` | Enable mouse mode | `true` |
-| `default-yank-register` | Default register used for yank/paste | `'"'` |
+| `mouse-yank-register` | Which register to use for mouse yanks. | `*` |
| `middle-click-paste` | Middle click paste support | `true` |
+| `default-yank-register` | Default register used for yank/paste | `'"'` |
| `scroll-lines` | Number of lines to scroll per scroll wheel step | `3` |
| `shell` | Shell to use when running external commands | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
| `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers | `"absolute"` |
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 24546908..e36c694f 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -4659,7 +4659,7 @@ fn yank_joined_to_primary_clipboard(cx: &mut Context) {
exit_select_mode(cx);
}
-fn yank_primary_selection_impl(editor: &mut Editor, register: char) {
+pub(crate) fn yank_main_selection_to_register(editor: &mut Editor, register: char) {
let (view, doc) = current!(editor);
let text = doc.text().slice(..);
@@ -4672,17 +4672,17 @@ fn yank_primary_selection_impl(editor: &mut Editor, register: char) {
}
fn yank_main_selection_to_clipboard(cx: &mut Context) {
- yank_primary_selection_impl(cx.editor, '+');
+ yank_main_selection_to_register(cx.editor, '+');
exit_select_mode(cx);
}
fn yank_main_selection_to_primary_clipboard(cx: &mut Context) {
- yank_primary_selection_impl(cx.editor, '*');
+ yank_main_selection_to_register(cx.editor, '*');
exit_select_mode(cx);
}
#[derive(Copy, Clone)]
-enum Paste {
+pub(crate) enum Paste {
Before,
After,
Cursor,
@@ -4805,16 +4805,15 @@ fn paste_primary_clipboard_before(cx: &mut Context) {
}
fn replace_with_yanked(cx: &mut Context) {
- replace_with_yanked_impl(
+ replace_selections_with_register(
cx.editor,
- cx.register
- .unwrap_or(cx.editor.config().default_yank_register),
+ cx.editor.config().default_yank_register,
cx.count(),
);
exit_select_mode(cx);
}
-fn replace_with_yanked_impl(editor: &mut Editor, register: char, count: usize) {
+pub(crate) fn replace_selections_with_register(editor: &mut Editor, register: char, count: usize) {
let Some(values) = editor
.registers
.read(register, editor)
@@ -4858,16 +4857,16 @@ fn replace_with_yanked_impl(editor: &mut Editor, register: char, count: usize) {
}
fn replace_selections_with_clipboard(cx: &mut Context) {
- replace_with_yanked_impl(cx.editor, '+', cx.count());
+ replace_selections_with_register(cx.editor, '+', cx.count());
exit_select_mode(cx);
}
fn replace_selections_with_primary_clipboard(cx: &mut Context) {
- replace_with_yanked_impl(cx.editor, '*', cx.count());
+ replace_selections_with_register(cx.editor, '*', cx.count());
exit_select_mode(cx);
}
-fn paste(editor: &mut Editor, register: char, pos: Paste, count: usize) {
+pub(crate) fn paste(editor: &mut Editor, register: char, pos: Paste, count: usize) {
let Some(values) = editor.registers.read(register, editor) else {
return;
};
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index b354df2b..5597d586 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -1071,7 +1071,7 @@ fn yank_main_selection_to_clipboard(
return Ok(());
}
- yank_primary_selection_impl(cx.editor, '+');
+ yank_main_selection_to_register(cx.editor, '+');
Ok(())
}
@@ -1116,7 +1116,7 @@ fn yank_main_selection_to_primary_clipboard(
return Ok(());
}
- yank_primary_selection_impl(cx.editor, '*');
+ yank_main_selection_to_register(cx.editor, '*');
Ok(())
}
@@ -1197,7 +1197,7 @@ fn replace_selections_with_clipboard(
return Ok(());
}
- replace_with_yanked_impl(cx.editor, '+', 1);
+ replace_selections_with_register(cx.editor, '+', 1);
Ok(())
}
@@ -1210,7 +1210,7 @@ fn replace_selections_with_primary_clipboard(
return Ok(());
}
- replace_with_yanked_impl(cx.editor, '*', 1);
+ replace_selections_with_register(cx.editor, '*', 1);
Ok(())
}
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index b25af107..9ffc3e87 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -1272,8 +1272,10 @@ impl EditorView {
};
if should_yank {
- commands::MappableCommand::yank_main_selection_to_primary_clipboard
- .execute(cxt);
+ commands::yank_main_selection_to_register(
+ cxt.editor,
+ config.mouse_yank_register,
+ );
EventResult::Consumed(None)
} else {
EventResult::Ignored(None)
@@ -1313,8 +1315,11 @@ impl EditorView {
}
if modifiers == KeyModifiers::ALT {
- commands::MappableCommand::replace_selections_with_primary_clipboard
- .execute(cxt);
+ commands::replace_selections_with_register(
+ cxt.editor,
+ config.mouse_yank_register,
+ cxt.count(),
+ );
return EventResult::Consumed(None);
}
@@ -1323,7 +1328,13 @@ impl EditorView {
let doc = doc_mut!(editor, &view!(editor, view_id).doc);
doc.set_selection(view_id, Selection::point(pos));
cxt.editor.focus(view_id);
- commands::MappableCommand::paste_primary_clipboard_before.execute(cxt);
+
+ commands::paste(
+ cxt.editor,
+ config.mouse_yank_register,
+ commands::Paste::Before,
+ cxt.count(),
+ );
return EventResult::Consumed(None);
}
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 6193a852..b7b4c442 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -298,6 +298,8 @@ pub struct Config {
pub scroll_lines: isize,
/// Mouse support. Defaults to true.
pub mouse: bool,
+ /// Which register to use for mouse yank.
+ pub mouse_yank_register: char,
/// Shell to use for shell commands. Defaults to ["cmd", "/C"] on Windows and ["sh", "-c"] otherwise.
pub shell: Vec<String>,
/// Line number mode.
@@ -1086,6 +1088,7 @@ impl Default for Config {
scrolloff: 5,
scroll_lines: 3,
mouse: true,
+ mouse_yank_register: '*',
shell: if cfg!(windows) {
vec!["cmd".to_owned(), "/C".to_owned()]
} else {