-
Notifications
You must be signed in to change notification settings - Fork 6.1k
helix: Add match operator #34060
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
helix: Add match operator #34060
Conversation
|
Thanks! This seems reasonable to me. There's been a lot of talk about moving helix out into more of its own thing; I think we should keep that option open and push for more of the code to live in (e.g. On the flip side. Are there other helix motions that want to be able to use object.range? If so, we could update |
|
I don't get it: Why are the tests failing? They pass on my laptop and marks work when running this in vim normal mode. |
There are also |
|
Looks like the test is failing on the merge of main and this branch, but passes on both branches separately. Let me know if you need help debugging why.. |
|
@fantacell should this still be a draft? |
I'm still working on those, but I think I'm almost done. |
|
I didn't know when writing this that helix itself doesn't have motions like selecting the next brackets |
- fix the operators' display in the status bar - fill the subword object placeholder - fix some spelling mistakes - fix a bug where the first and last words in a buffer couldn't be selected
|
Right now typing something like |
one object. This makes return types shorter and makes it easy to add an extra helix object entirely. Also add logic for the sentence and paragraph text objects. The way this is implemented would make it easy to for example ignore brackets after a backslash.
|
I think feature wise this is ready, more can be added later. But I think implementing this similarly to to word motions might not have been so good; paragraph and sentence text objects are pretty slow in debug builds. Other than that it seems fine in helix mode, but @ConradIrwin by moving the keybindings around between contexts we broke the tests for vim mode. Before, the first char of "] {" in |
|
Hmm; in theory iterating over strings manually shouldn't be very notably slower than regexes. Are we doing a lot of co-ordinate translations between DisplayPoint and Point etc.? Looks like the clippy monster is not happy yet |
|
It should be appeased now.
Oh, yes actually, |
|
Happy to look into it if it's really slow – for large long-range queries we should use tree-sitter; but for smaller things character iteration should be fine (as long as we're not backtracking too much..) |
|
It feels ok to me in release builds right now. But I can store more state in between searches to avoid backtracking, that would be needed for "m i m" anyway. I could do that and switch to only offsets, either now in this PR or later. If it is ok for now, the only problem left is the keybinding conflict. |
|
Much better. |
|
hey @fantacell great job with this PR. Although it looks like a lot of boundary-related logic got duplicated, if you have @ConradIrwin blessing for this - it probably is the correct way to go. Lovely to see helix-related operators being implemented thoroughly. I'd be interested to look into how we can integrate with #34798 next. |
thanks! About the duplication: In vim mode every object kind handles the finding itself, which is hard to access to then find the "]" and "[" ranges. In this PR, the only object specific thing is what is and isn't a start / end depending on the surrounding chars. The finding itself is then only done by the "]", "[", "mi" and "ma" operators. Also, "vi" and "mi" ranges are in many cases slightly different and I didn't want to add tons of checks for mode to then cover every edge case. An advantage of this would be that tree-sitter text objects should be easy to add, as well as kakoune style "]" and "[", which is how helix "]p" and "[p" seem to actually work. I just haven't found a way to express that with the keymap. If you (or anyone) have an idea for that, it would be welcome.
How to access this over the keymap does seem like a real problem right now. |
|
Sorry for the delay here, I've been wrapped up in https://agentclientprotocol.com for the last few weeks. I think the problem is just we were missing the Feeling close though :D. @Romanisch - re duplication; I think it's a better structure overall if helix matching is "consistently slightly different" to not try and share too much code (because it ends up with a bunch of nested booleans and ifs in the middle of stuff that's already quite fiddly). So it seems clearer to have two methods that do the similar-but-not-quite-the-same things. (In v0 of helix mode, re-using vim code made more sense because the differences didn't matter) |
|
Yes; thank you for fixing the keybinding stuff, it was nice to see green for once. But I found a bug with |
|
@fantacell, I have combined some of my previous work with the now closed Select mode PR into this draft: I found it quite hard to figure out how to operate helix_move_cursor in select move, since perform collapse of selection. It's not longer possible to wrap it as i've done before. Do you have some idea how to implement it without regressions? |
|
@romaninsh Hm right now the helix functions all kind of "do" and don't "return". You could add something like Though just to be sure: Have you seen the last comment #34136 (comment)? |
|
@fantacell i've seen that comment from @eliaperantoni and I asked to credit them for the change. However I also wanted to add some of my fixes in my PR, making helix mode more sticky and added some simplifications. Also i have grouped up keybindings which apply to both normal and visual mode, to avoid duplication, while keeping visual mode clean otherwise. i'll think a bit longer on how to properly re-use your movement functions in select mode, i can't see any clear way to implement now. |
|
No worries at all about the credits! The fact that I'm mentioned here is credit enough ❤️. I got a bit busy with a new job and I couldn't continue my PR but it's totally okay that someone else is working on this :) Thanks for the contribution @romaninsh this looks great! |
This is an implementation of matching like "m i (", as well as "] (" and
"[ (" in `helix_mode` with a few supported objects and a basis for more.
Release Notes:
- Added helix operators for selecting text objects
---------
Co-authored-by: Conrad Irwin <[email protected]>
Please credit @eliaperantoni, for the original PR (#34136). Merge after (#34060) to avoid conflicts. Closes #33838 Closes #33906 Release Notes: - Helix will no longer sometimes fall out into "normal" mode, will remain in "helix normal" (example: vv) - Added dedicated "helix select" mode that can be targeted by keybindings Known issues: - [ ] Helix motion, especially surround-add will not properly work in visual mode, as it won't call `helix_move_cursor`. It is possible however to respect self.mode in change_selection now. - [ ] Some operations, such as `Ctrl+A` (increment) or `>` (indent) will collapse selection also. I haven't found a way to avoid it. --------- Co-authored-by: fantacell <[email protected]> Co-authored-by: Conrad Irwin <[email protected]>
This is an implementation of matching like "m i (", as well as "] (" and "[ (" in
helix_modewith a few supported objects and a basis for more.Release Notes: