-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add system clipboard yank and paste commands #310
Conversation
ffbc017
to
dfe4472
Compare
I think you have to add the new commands to the commands list here: helix/helix-term/src/commands.rs Line 144 in dfe4472
|
Potentially controversial but I think |
I usually replace the default |
I prefer the register approach TBH - |
I will have to change the type of command for that (currently it's "typable").
Oh, let me add this then!
Regarding the register approach : it works well when multi selection is not a first class citizen like in (neo)vim, but it's not ideal in our case. System clipboard is unique and destroy distinction between selections, and you have multiple interpretations : you could join all selections together OR only take one of the selection when yanking to system clipboard. When pasting, your only option is pretty much to paste the same thing for all the selections. And when yanking and directly pasting from the register, you get a completely different behavior than the other registers, which while making sense, is arguably surprising. In (neo)vim, this register behavior is indeed a bit different because it will also paste from / yank to system clipboard, but you could use it like a normal vim register. In Helix, you couldn't use that register like a normal helix register. That's why I decided to not implement this approach at least for now and the more I think about it, the more I don't see this as the right default approach for Helix. However, I would like to enable people to implement this using user config through future plugins system (by either using hooks or defining a custom function). |
|
@sudormrfbin Yeah, we started with the |
use anyhow::Result; | ||
use std::borrow::Cow; | ||
|
||
pub trait ClipboardProvider: std::fmt::Debug { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this trait gives us the option to introduce more providers later, is that the intent here? Otherwise we could also simply use Option<CommandProvider>
and avoid the Box<dyn T>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that was the intent, but I agree this could as well be Option<CommandProvider>
right now. I can change that if you prefer. It was maybe a bit premature.
let max_to = doc.text().len_chars().saturating_sub(1); | ||
let to = std::cmp::min(max_to, range.to() + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern is now frequent enough that maybe we should add a helper function doc.clipped_range
or something, it would help with #224. Can be done over there I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it helps in #224, it's probably more useful if done there indeed. I'll make sure to use the helper if it gets merged before my PR.
Ahh yeah I didn't think about the disparity between yanking multiple selections and pasting a single selection. Makes sense 👍 |
This commit adds six new commands to interact with system clipboard: - clipboard-yank - clipboard-yank-join - clipboard-paste-after - clipboard-paste-before - clipboard-paste-replace - show-clipboard-provider System clipboard provider is detected by checking a few environment variables and executables. Currently only built-in detection is supported. `clipboard-yank` will only yank the "main" selection, which is currently the first one. This will need to be revisited later. Closes helix-editor#76
System clipboard integration exists now in two favors: typable and mappable. Default mappings are: - SPC p: paste clipboard after - SPC P: paste clipboard before - SPC y: join and yank selection to clipboard - SPC Y: yank main selection to clipboard - SPC R: replace selections by clipboard contents
f15ea25
to
3e248f3
Compare
PR updated and rebased on master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on wayland, works great!
What does that mean? |
Let me try to clarify my paragraph. In (neo)vim if you copy a selection "A" to The behavior would be the same in helix as well when working with a single selection, however helix supports multi selections and system clipboard does not supports multi values. Since there is no right default choice for helix with |
This commit adds six new commands to interact with system clipboard:
System clipboard provider is detected by checking a few environment
variables and executables. Currently only built-in detection is
supported.
clipboard-yank
will only yank the "main" selection, which is currently the firstone. This will need to be revisited later.
Closes #76