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

add C-y to yank picker selection to clipboard #3786

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,22 @@ impl<T: Item + 'static> Component for Picker<T> {
ctrl!('t') => {
self.toggle_preview();
}
ctrl!('y') => {
if let Some(contents) = self.selection() {
let contents = contents.sort_text(&self.editor_data).to_string();
Copy link
Member

@CBenoit CBenoit Sep 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Oops, I forgot to add the comment. Here it is.)

Since the sort text is not always equal to the stringified label depending on the Item, maybe we specifically want String::from(contents.label(&self.editor_data)) so that it always copies what is actually rendered in the picker minus the style?

Also when you need a String by consuming a Cow<str>, you might want to use into_owned instead in order to steal the String if it is already allocated.

if let Err(e) = cx
.editor
.clipboard_provider
.set_contents(contents, helix_view::clipboard::ClipboardType::Clipboard)
{
cx.editor
.set_status(format!("Couldn't set system clipboard content: {}", e))
} else {
cx.editor
.set_status("yanked picker selection to system clipboard");
}
}
}
_ => {
self.prompt_handle_event(event, cx);
}
Expand Down