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 yank_joined command #7195

Merged
merged 1 commit into from Jun 16, 2023
Merged

Add yank_joined command #7195

merged 1 commit into from Jun 16, 2023

Conversation

spectre256
Copy link
Contributor

Resolves issue #6888 by adding a command to join all selections and yank them to the specified register. The typed command takes an argument as the separator to use when joining the selections.

This command works the same as yank_joined_to_clipboard except that it yanks to a register.

Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

I am not sure if introducing a new command is a right thing tondo here. I think we could make the register configurable instead (so the yank_joined command yanks to clipbaors by default but you can specify a different register). I am not sure if that's already possible or if that requires #6985

CC @the-mikedavis

let (view, doc) = current!(editor);
let text = doc.text().slice(..);

let values: Vec<String> = doc
Copy link
Member

Choose a reason for hiding this comment

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

The existing code does this too but this code ks allocating twice here which is a bit unnecessary/potentially slow for large selections so maybe we can fix that while we are working on this anyway.

Instead you can iterate the Selection::slices text.slice(range) and then push_str to the result. This will require special handeling for the first element but you can just use that to intalize the string: let mut res = slices.next,().unwrap().to_string()

Copy link
Contributor Author

@spectre256 spectre256 Jun 1, 2023

Choose a reason for hiding this comment

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

Thanks for your feedback! I think I've fixed it.

Also, about introducing a new command: since the register is already configurable, I think it should be fine to leave as is. Once the special registers for the clipboard is added, it will be able to be used with the system clipboard. (and the yank_joined_to_clipboard command can be removed) The " register seems like a sane default to me. This also reflects the discussion in #6888.

Or did you mean the typed command? I could add an argument for which register to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh and one more thing: there's an experimental intersperse_with method for iterators on nightly that can be enabled with #![feature(iter_intersperse)]. Since it's experimental, I didn't use it, but it would simplify some of the code. Should I just add a note in the comments or something?

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Jun 5, 2023
@the-mikedavis
Copy link
Member

Ideally join+yank to the clipboards would be implemented in terms of this command. I would prefer to add this and eventually remove the yank_to_*_clipboard commands. I think this command could be useful on its own too.

@the-mikedavis the-mikedavis self-requested a review June 7, 2023 23:11
@spectre256
Copy link
Contributor Author

Hey everyone, is there anything else I could do to get this merged? No rush, just checking in :)

@the-mikedavis
Copy link
Member

No we just need to find time to review the changes. I have a bunch more PRs in my queue to look at than usual since I was away for a while but I'd like to look at this sooner rather than later

helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
@the-mikedavis the-mikedavis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Jun 13, 2023
@spectre256 spectre256 force-pushed the master branch 3 times, most recently from ae0a33a to d93728e Compare June 13, 2023 22:08
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

Just a minor thing, otherwise this looks good

if event != PromptEvent::Validate {
return Ok(());
}

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we do this consistently in typable commands but we can give some feedback when the command gets more arguments than expected:

ensure!(args.len() <= 1, ":yank-join takes at most 1 argument");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just updated it! Would it be helpful to make a pr to add this to the other commands as necessary?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think it would be good to have some feedback especially on the new/save file operations like new, write, format, etc 👍. Discarding arguments silently seems potentially confusing to me

Resolves issue helix-editor#6888 by adding a command to join all selections and yank
them to the specified register. The typed command takes an argument as
the separator to use when joining the selections.
@the-mikedavis the-mikedavis added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 16, 2023
@pascalkuthe pascalkuthe merged commit d8b7232 into helix-editor:master Jun 16, 2023
6 checks passed
Triton171 pushed a commit to Triton171/helix that referenced this pull request Jun 18, 2023
Resolves issue helix-editor#6888 by adding a command to join all selections and yank
them to the specified register. The typed command takes an argument as
the separator to use when joining the selections.
Xalfer pushed a commit to Xalfer/helix that referenced this pull request Jun 19, 2023
Resolves issue helix-editor#6888 by adding a command to join all selections and yank
them to the specified register. The typed command takes an argument as
the separator to use when joining the selections.
@gabydd gabydd mentioned this pull request Jun 23, 2023
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
Resolves issue helix-editor#6888 by adding a command to join all selections and yank
them to the specified register. The typed command takes an argument as
the separator to use when joining the selections.
@David-Else
Copy link
Contributor

I think I am missing something obvious, but how exactly do I yank to a chosen register. I make multiple selections and run this command using :yank-join and it yanks and joins to ".

Once the special registers for the clipboard is added, it will be able to be used with the system clipboard. (and the yank_joined_to_clipboard command can be removed)

This has happened now.

@the-mikedavis
Copy link
Member

:yank-join takes a string to join the selections as its argument rather than a register to yank into. You can select a register ("*) and then execute yank_joined for example from the command picker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants