gabesoft / evil-mc

Multiple cursors implementation for evil-mode
MIT License
383 stars 35 forks source link

Add command to undo last added cursor #86

Closed yuhan0 closed 5 years ago

yuhan0 commented 5 years ago

This PR adds functionality of undoing the last added cursor, which is available in other editors' multiple cursor implementations. This makes it possible to correct the common mistake of creating too many cursors (e.g when hitting C-n past the intended range), without having to start all over again.

Also changes the binding of "gru" to undo the very last added cursor instead of deleting all cursors, in line with the meaning of "u = undo last action" in evil mode.

The previous binding of evil-mc-undo-all-cursors is moved to "grq" ("quit")

gabesoft commented 5 years ago

This functionality is already available under the grp keybinding. For skipping/undoing backwards use grp, for skipping forward use grn or C-t.

yuhan0 commented 5 years ago

That's only the case for cursors created by matching (where evil-multiedit or iedit tends to be a better option). For line-based cursors created by "grj"/"grk" (which is 99% of what I use evil-mc for), or even arbitrary positions with "grh", I believe this functionality does not currently exist.

quick demo: demo

gabesoft commented 5 years ago

I see. I'd prefer to fix grp to work with cursors created by grj rather than create yet another shortcut. Also , also the tests must pass before I can consider merging a pull request. By, the way you can use a number with grj/grk to create exactly the number of cursors you want. But, I agree that it would be nice to have the ability to undo individual cursors regardless on how they were created.

gabesoft commented 5 years ago

To run the tests locally do in the evil-mc directory:

yuhan0 commented 5 years ago

Thanks, I'll look into running the tests :)

With respect to "fixing" grp to handle this case - I personally feel that overloading skip-and-goto-prev-match to fit the user's intention of "undo that last mistaken cursor" isn't a very good idea and would hurt discoverability.

Besides, "undo last cursor" is a primitive action in other editors like Sublime Text and VS Code with native multiple-cursor support, I think it's reasonable to expect similar functionality under a top level shortcut.

yuhan0 commented 5 years ago

The test failure appears to be due to the "gru" keybinding for evil-mc-undo-all-cursors being changed.

I'm not quite familiar with the testing framework being used here, but it seems that replacing "gru" in features/evil-mc-copy-paste.feature with my proposed replacement "grq" makes the current tests pass.

I went ahead and pushed that change in order for the tests to pass - open to discussion about the default bindings of course :)

gabesoft commented 5 years ago

Thanks @yuhan0 looks good. One last thing, could you also update README.org to reflect the new keybindings.

yuhan0 commented 5 years ago

Okay, just got around to it :) By the way would you prefer having "grU" as the replacement binding for undo-all-cursors? In my mental model I think of it as "quitting" multiple cursor mode, but the command name suggests it as a "stronger" version of undoing cursors.

yuhan0 commented 5 years ago

Also pushed a small correction - some -> cl-some from the cl-lib library

gabesoft commented 5 years ago

I like grU but grq is easier to type and since this is a pretty common operation I think we can leave it as is.

gabesoft commented 5 years ago

Merged! Thanks @yuhan0