-
-
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 ability to match in next and previous char pairs (2) #11695
base: master
Are you sure you want to change the base?
Add ability to match in next and previous char pairs (2) #11695
Conversation
Note: the first commit is essentially just the changes linked in the comment here. I left the two |
Bumping this 🙏 |
If I jump to a function, would this patch still support jumping to next and previous function? |
Yes, that still works as it does currently on master |
@the-mikedavis apologies for the ping, wondering if you'd mind taking a look at this? 🙏 |
I do want to take a look at this soon but I'm about to be away for a while. I have a note written down to give this a look once I'm back in a 2ish weeks. (I'm in favor of the feature, I just haven't looked at the changes yet) |
@@ -172,6 +178,17 @@ pub fn find_nth_pairs_pos( | |||
|
|||
let (open, close) = get_pair(ch); | |||
let pos = range.cursor(text); | |||
let (pos, n) = match find_type { | |||
FindType::Surround(n) => (pos, n), | |||
FindType::Next(n) => match search::find_nth_next(text, open, pos, n) { |
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.
Using plaintext search routines isn't right here. This should be based on tree-sitter. The plaintext search gets thrown off by string literals.
In general I think reusing the surround function won't work too well here. The surround function mostly reuses other functions (match_bracket:: and search::) to find pairs and only adds logical necessary for surround. For forwards/reverse search you are looking for a pair fist and then a single (simpler) call to match_bracket/search would suffice.
I would probably be ok with not implementing the tree-sitter based forward/reverse search for now but I would definitly want to see this as a seperate function (likely directly within textobject.rs).
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.
Sorry not sure I'm fully following - mi{
doesn't use treesitter as far as I can tell, so would we want ]{
to behave any differently?
Also, I decided to go with the option of finding the first char within a pair and then using textobject_pair_surround
as this allows selection of ranges between characters where the direction is not clear from the bracket e.g. between |
characters. ]|
works fine to jump between pairs of |
in something like foo|bar|baz|
, but that wouldn't work if first searching for the |
and then calling one of the match_brackets
functions. I'm sure I could overcome this by making a bunch of changes in match_brackets
but I thought that would add a lot of code - do you think that option would be preferable, or is there a different approach I'm missing?
Adds the ability to match inside/around the next or previous matching character pair: for instance, with the cursor as
█
below:typing
]"
would select the contents of the string (i.e.bar
).Screen.Recording.2024-09-15.at.10.20.34.mov
Supersedes #11260 based on discussion there.
Partially resolves: