-
Notifications
You must be signed in to change notification settings - Fork 165
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
Implement vi-mode "Yank" (copy): #868
Conversation
7e2619d
to
af86266
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.
Thanks for giving this a shot and putting in the work! One thing that makes me hesitant about this, that the copying we do does not work with multipliers at all as each EditCommand
will update the clipboard. Also operations you define in terms of two EditCommand
s suffer the same unfortunate fate.
One solution to that would be to do extra state management around clipboard but keep the old edit commands (suggested in #631 ) or otherwise rethink how we implement the vi mode interface to use an internal selection build up from the motion before performing the action. The latter would require way fewer additional EditCommand
to be maintained, like the ones you propose here. Related issues where that came up was the impl of #849 where there are cases where the chaining of EditCommands did not achieve the expected result.
What you say are valid concerns and I do agree in the future a re-think/refactor is needed to make Vi mode elegant and better. |
src/edit_mode/vi/command.rs
Outdated
Self::YankInside(left) if is_valid_change_inside_left(left) => { | ||
let right = bracket_for(left); | ||
vec![ | ||
ReedlineOption::Edit(EditCommand::CopyLeftBefore(*left)), | ||
ReedlineOption::Edit(EditCommand::CopyRightBefore(right)), | ||
] | ||
} | ||
Self::YankInside(right) if is_valid_change_inside_right(right) => { | ||
let left = bracket_for(right); | ||
vec![ | ||
ReedlineOption::Edit(EditCommand::CopyLeftBefore(left)), | ||
ReedlineOption::Edit(EditCommand::CopyRightBefore(*right)), | ||
] | ||
} |
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.
As those are guranteed to be broken for all cases where you are not on the beginning of the text object (putting the left half in the clipboard and then overwriting with the right half) I would omit them until we have a better solution. Yes to shipping but let's not ship broken stuff.
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 was indeed my mistake initially. Thanks for helping review! This specific issue should be addressed in #874 , atomic Cut/CopyInside pair of brackets/quotes.
src/edit_mode/vi/parser.rs
Outdated
(Some(Command::Delete), ParseResult::Incomplete) | ||
| (Some(Command::DeleteChar), ParseResult::Incomplete) | ||
| (Some(Command::DeleteToEnd), ParseResult::Incomplete) | ||
| (Some(Command::Delete), ParseResult::Valid(_)) | ||
| (Some(Command::DeleteChar), ParseResult::Valid(_)) | ||
| (Some(Command::DeleteToEnd), ParseResult::Valid(_)) | ||
| (Some(Command::Yank), ParseResult::Valid(_)) | ||
| (Some(Command::Yank), ParseResult::Incomplete) | ||
| (Some(Command::YankInside(_)), ParseResult::Valid(_)) | ||
| (Some(Command::YankInside(_)), ParseResult::Incomplete) => Some(ViMode::Normal), |
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.
Let's not forget to rebase/merge onto the updated main branch when landing #867
pub(crate) fn copy_from_start(&mut self) { | ||
let insertion_offset = self.line_buffer.insertion_point(); | ||
if insertion_offset > 0 { | ||
self.cut_buffer.set( | ||
&self.line_buffer.get_buffer()[..insertion_offset], | ||
ClipboardMode::Normal, | ||
); | ||
} | ||
} |
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 haven't gone through all of those to check if their indexing is correct. That's an annoying part to deal with this level of duplication for the different versions referring to the same text-objects/motions.
/// Copy from the start of the buffer to the insertion point | ||
CopyFromStart, | ||
|
||
/// Copy from the start of the current line to the insertion point | ||
CopyFromLineStart, |
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.
For the users trying to configure their emacs mode having all those extra variants certainly adds some potential for confusion, and when we remove them for a simpler VI mode more breaking changes where we hope people don't try to depend on them.
bb76b01
to
1f73f9a
Compare
Indeed I see a common pattern Move/Cut/Copy + selection range (word, big word, line end, etc.). 3+ actions plus ~10 selections give us numerous |
is anything blocking this? I think we're all in agreement that the vi mode interface should be reworked eventually but this PR seems like a helpful stop-gap for now |
I don't think there's any block except for the dependent PRs #867 , #874. |
Should be good for a rebase/merge following the merge of #867. Is the refactor proposed/documented in #874 already part of this branch or am I misreading this? Otherwise I am good with landing this (@132ikl if you want to look into something feel free to chime in otherwise I would give the green light after resolving the branch) |
1f73f9a
to
eecf12b
Compare
I've rebased this to be on top of #874. Current PR includes all of #874 with one additional commit for Vi-Yank. Once 874 is merged, we can merge this PR with a single-clean commit for yank. |
sounds good, let me or @sholderbach know when you update the branch |
- Vi Command; - Editor Command; - Editor methods; - Mode changes back to Normal after yank
eecf12b
to
6cfb08c
Compare
Done ready for review :D |
thank you!! |
Implement vi-mode "Yank" (copy):
- Vi Command;
- Editor Command;
- Editor methods;
- Mode changes back to Normal after yank
Note only last commit in this PR should be reviewed as part of this PR as this is on top of: