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
Multi selection search #12
Conversation
This adds the ability to run an incremental search via the `modaledit.search` command with multiple cursors. This is particularly useful for emulating vim's `f` and `d` commands or `vim-sneak` with multiple cursors. Cursor motion to specific characters for each cursor is quite useful.
Hi! Thanks a lot for contributing! I checked out your pull request and spend quite a while testing the new feature. I have to say that while it kind of works, there are lot of edge cases I am not so happy with. When I first got issue #5, I thought about it briefly, and came up with problems that I could not figure out immediately, like:
Your implementation answers question 1. by selecting the same match multiple times which effectively looses multiple cursors. That is a simple solution, but one could argue that it reduces the usefulness of the feature as this happens quite often. Jumping to previous or next match also looses multiple cursors - at the latest when a search string is not found any more. Skipping same matches would complicate the logic of the search considerably, so I understand why you didn't take that approach :-) Regarding question 2, your implementation just shows the primary selection. Again, kinda works but editing a range of text you can't see is not something most users would do, so this also reduces the utility of the feature. This was my reasoning back then why I gave up on the feature. I can see the value of it in a scenario, where you use Third issue that I found is that So, for all these reasons, unfortunately I have to reject your pull request. The search command is by far the most complicated command in the extension as it is, so I would prefer not to make it any more complex. I cannot give you an alternative solution how to achieve exactly the same feature, but here are some pointers. If you just want to implement Vim's You can get the searched character(s) by using a range in the key bindings. An example of this can be found here. |
Thanks for your very careful review and feedback. I have some thoughts on your comments. TL;DR: I am open to trying to think through this more and generate a design that would be to both our likings w.r.t to the issues you raise. I think it is a worthwhile feature to have. However, if you're settled on this not being the right approach for you, we can just agree to disagree and I'll fork and add features on my own. Let me know what you think! As I understand your comments, you raise 2 design questions and have identified a bug in my implementation. With respect to the design questions:
With respect to the bug you point out: Basically, if I understand correctly, you're talking about a scenario in which there are a different number of search tokens in the neighborhood of each cursor, so when you search forwards and backwards the cursor could be at a different position relative to the start of the search. If I understand correctly, I think the immediate issue is fixable: rather than using a delta, represent the start of the search as a range rather than a position, and use the start or end of the range depending on the direction of the search, on a per cursor basis. Or did I miss something about how the delta works? Though If I get your real problem with this, it is that you're not convinced all edge cases have been considered: i.e. there could be more bugs you haven't thought of. However, I am trying to imagine a scenario in which multi-cursor searching would actually be useful for the sort of situation where the search goes awry in the way you describe. In general the benefit of searching with multiple selections is that you can identify tokens in the neighborhood of a symbol, on the basis of shared syntactic structure at the different locations (e.g. quickly move to the next parenthesis, move to the next if statement, move to the next else statement); if there are a different number of search tokens near one of the cursors, then the structure of the text near that cursor is necessarily different than the others, and so it's not clear that any mutations you made at those location could possibly useful. My point is that any situation where the cursors cross paths or go in different directions would mean that you are editing text within each selection location that isn't similar in structure and the whole point of multi-selection would disappear. Searching is really only useful when the behavior at each cursor is uniform. Ideally, the implementation should handle those situations where it isn't uniform gracefully, so that reversing an action works as expected, but as a user I've already entered an undesired state if this happens in the first place and good old "cursor" or "soft" undo works just fine. I don't think implementing this only for the use case of Clearly there is some work to improve these issues with this PR. But I'm happy to try out some approaches to make those improvements if you think the collaboration would be worthwhile. Just let me know! |
Hi again! Sorry for being unresponsive for a while. Life has kept me busy with other things than programming lately. This is a lengthy response, so I divide it to separate sections trying to make my points clearer. Disappearing cursorsI have nothing against the idea of the PR in general. I just prefer that commands have clear specifications on how they work in all use cases. In this case the behavior of the Cursors out of view portAlso the second issue should be documented as a caveat that you cannot always see all cursor locations while the incremental search is active. That might spawn a feature request that you could jump between the cursors while the search is active using tab key, for example. You could bind the tab key to General guidance about PRsThe point is that, instead of these features being accidental they should be acknowledged and documented. That's why I have spent the effort of writing the code in literate style, so that all of these assumptions would be stated in the documentation. As a practical guidance to submitting PR's my wish is that all of these changes in functionality would be documented in the comments. Then it would be easy to see that all of the aspects have been considered and taken care of. The problem in the
|
Thanks again for the thorough response. I'm totally sympathetic to the time lag. That sounds like a reasonable plan to me. I can pick things up for 2-3 once you are done with 1. In the revised PR, I understand that you want the literate documentation to explain the behavior and identify the limitations (e.g. selection overlap, cursors disappearing). Later on, I'd be interested in implementing the feature to change which cursor is primary (and therefore where the viewport is located) with e.g. tab (or whatever binding a user prefers), that's something I'd been thinking of anyways (as I'm really inspired by Kakoune's approach to modal editing). |
If I understand correctly, you've now implemented this feature in the latest master. I think this is safe to close, right? |
Hi There!
First of all, thanks for the great extension! I love it, and use it daily. The clarity of your tutorial and documentation made this a joy to extend for my own purposes.
Here is a change that makes it possible to use multiple cursors with the search command. The idea is that it allows you to emulate commands like f and d in vim for each cursor. I am making use of it in my daily work now.
I also have been working on an ability to record "macros"; right now it only records normal mode keys, but seems like it should be possible to handle insert mode recording as well (though I don't know if it would be perfect). I will create a separate pull request for that once I am happy with the functionality.
This would close #5