Skip to content
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

Yank to system clipboard #76

Closed
hovsater opened this issue Jun 3, 2021 · 8 comments · Fixed by #310
Closed

Yank to system clipboard #76

hovsater opened this issue Jun 3, 2021 · 8 comments · Fixed by #310
Assignees
Labels
C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@hovsater
Copy link
Contributor

hovsater commented Jun 3, 2021

It would be nice if you could yank the current selection to the system clipboard.

@archseer
Copy link
Member

archseer commented Jun 3, 2021

I'd like to see this added, I recommend using https://github.com/alacritty/copypasta since it also includes Wayland support.

Both yank and delete always use register::set:

register::set(reg, values);

Which is a dumb hashmap with a lock right now:

pub fn get(register: char) -> Option<Vec<String>> {

I think we should special case certain registers inside set/get, in this case + should interface with the clipboard instead of the map.

The register changing via " (i.e. "+y/"+p) could be a command that uses on_next_key to wait for the next key, then change the register on the context, similar to how count is handled inside ui/editor.rs (set_register would have to be added to commands::Context).

on_next_key example:

cx.on_next_key(move |cx, event| {
if let KeyEvent {
code: KeyCode::Char(ch),
..
} = event
{
// TODO: temporarily show SPC in the mode list
match ch {
'f' => file_picker(cx),
'b' => buffer_picker(cx),
'v' => vsplit(cx),
'w' => {
// save current buffer
let (view, doc) = cx.current();
doc.format(view.id); // TODO: merge into save
tokio::spawn(doc.save());
}
'c' => {
let view_id = cx.view().id;
// close current split
cx.editor.close(view_id, /* close_buffer */ false);
}
// ' ' => toggle_alternate_buffer(cx),
// TODO: temporary since space mode took it's old key
' ' => keep_primary_selection(cx),
_ => (),
}
}
})
}

@archseer archseer added C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much labels Jun 3, 2021
@hovsater hovsater changed the title feat: Yank to system clipboard Yank to system clipboard Jun 3, 2021
@CBenoit
Copy link
Member

CBenoit commented Jun 4, 2021

If no one is working on that yet, I'll take it
EDIT: I gave a try

CBenoit added a commit to CBenoit/helix that referenced this issue Jun 5, 2021
Selection is copied into system clipboard when yanking to register `+`.

Close helix-editor#76
CBenoit added a commit to CBenoit/helix that referenced this issue Jun 5, 2021
Selection is copied into system clipboard when yanking to register `+`.
internal register `+` is still updated because we want to keep multicursor
capabilities when pasting later.

Closes helix-editor#76
CBenoit added a commit to CBenoit/helix that referenced this issue Jun 5, 2021
Selection is copied into system clipboard when yanking to register `+`.
internal register `+` is still updated because we want to keep multicursor
capabilities when pasting later.

Closes helix-editor#76
CBenoit added a commit to CBenoit/helix that referenced this issue Jun 7, 2021
Selection is copied into system clipboard when yanking to register `+`.
internal register `+` is still updated because we want to keep multicursor
capabilities when pasting later.

Closes helix-editor#76
CBenoit added a commit to CBenoit/helix that referenced this issue Jun 7, 2021
Selection is copied into system clipboard when yanking to register `+`.
internal register `+` is still updated because we want to keep multicursor
capabilities when pasting later.

Closes helix-editor#76
@archseer
Copy link
Member

archseer commented Jun 7, 2021

Some discussion on the implementation: #119 (comment)

@CBenoit
Copy link
Member

CBenoit commented Jun 7, 2021

We also discussed on matrix about not using registers, for example using commands (clipboard-yank, clipboard-paste), to handle pasting and yanking from system clipboard.
This approach is similar to emacs and kakoune.

idk if this helps inform anything but in kakoune i set user y as yank to clipboard and user p as paste from clipboard and am reasonably happy with that. it doesn't let me do fancy things like idk, copying to the clipboard from somewhere else and executing that as a macro, but i don't really find myself needing more functionality often
since kakoune lacks a + register in the first place
especially since if you don't treat it as a register then you can make the semantics different from registers in the ways that they fundamentally differ

By ash from matrix (I don't know your GitHub ID)

@pickfire
Copy link
Contributor

pickfire commented Jun 8, 2021

We also discussed on matrix about not using registers, for example using commands (clipboard-yank, clipboard-paste), to handle pasting and yanking from system clipboard.

I still think using registers is a cleaner approach. Because we have quite some keys that work with clipboard, like ctrl-r * later if we want to paste from clipboard in insert mode.

@tdupes
Copy link

tdupes commented Jun 13, 2021

Could helix support OSC 52 as a simpler alternative? that is if we only care about yanking to the clipboard and not from it.

@CBenoit
Copy link
Member

CBenoit commented Jun 13, 2021

I guess it could easily be supported as a plugin. I'm not sure if this is useful enough to be part of the core (I personally never used it).

@tdupes tdupes mentioned this issue Jun 14, 2021
@pickfire
Copy link
Contributor

I guess it could easily be supported as a plugin. I'm not sure if this is useful enough to be part of the core (I personally never used it).

I wish it is in core, I always use this. I missed this in kakoune and I had to manually copy out the region with lots of spaces in kakoune, bad experience.

CBenoit added a commit to CBenoit/helix that referenced this issue Jun 18, 2021
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
CBenoit added a commit to CBenoit/helix that referenced this issue Jun 18, 2021
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
CBenoit added a commit to CBenoit/helix that referenced this issue Jun 20, 2021
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
archseer pushed a commit that referenced this issue Jun 20, 2021
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 #76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants