-
-
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 yank_joined command #7195
Add yank_joined command #7195
Conversation
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 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
helix-term/src/commands.rs
Outdated
let (view, doc) = current!(editor); | ||
let text = doc.text().slice(..); | ||
|
||
let values: Vec<String> = doc |
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.
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()
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.
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?
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.
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?
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. |
Hey everyone, is there anything else I could do to get this merged? No rush, just checking in :) |
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 |
ae0a33a
to
d93728e
Compare
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.
Just a minor thing, otherwise this looks good
if event != PromptEvent::Validate { | ||
return Ok(()); | ||
} | ||
|
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 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");
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.
Just updated it! Would it be helpful to make a pr to add this to the other commands as necessary?
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 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.
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.
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.
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
This has happened now. |
|
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.
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.
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.