Improve logic for obtaining surrounds range in Vim mode
now correctly retrieves range in cases where escape characters are present. Fixed #10827
Release Notes:
- vim: Fix logic for finding surrounding quotes to ignore escaped characters (#10827)
There are some issues with this code. When iterating with chars_after, I want to use a sliding window of size 2 to check if the second character is the matching character and, in this case, whether the first character is an escape character. However, using chars_after in conjunction with tuple_windows leads to an edge case. During the first check, we consider the character after the current cursor position as ch, and the character after that as after_ch. But we need to use after_ch to determine whether it's the corresponding character. If ch is already the correct character, we'll miss it. Even if we don't miss it, for instance if we use ch for the check, we can't get its preceding character.
So, I'm considering whether we could pass the point of the preceding position when calling chars_after. It might not seem elegant since it's only for handling the first iteration, and we'd only use it to check if the value at the previous position is an escape character.
If anyone can give advice, it would be appreciated
That's roughly what I ended up doing everywhere else, so seems fine. You still need to handle the edge-case at the start of the buffer, etc.
Alternatively you can keep track of the previous character outside the loop and initialize it with the prior char, so you don't need to use the with_tuples thing.
Thanks for adding a test!
That's roughly what I ended up doing everywhere else, so seems fine. You still need to handle the edge-case at the start of the buffer, etc.
Alternatively you can keep track of the previous character outside the loop and initialize it with the prior char, so you don't need to use the with_tuples thing.
Thanks for adding a test!
Decided to use an external variable to track this value XD, and traversed forward I continued to use windows, so maybe the code would be simpler, otherwise we would need another variable to track ch and range, and of course we can also use variable tracking, like after
Thanks!