fix infinite loop for argument object not supported by % #285
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the
argument
textobject is modified ando
contains a character that is not supported by % (or the matchpairs do not contain that character):then using this textobject can result in Vim freezing if the unsupported character is located inside of a pair of matching symbols.
For example, pressing
daa
with the cursor beforewould freeze the editor.
The issue is that the function for finding the boundary of the argument uses
%
on the found symbol, and if%
doesn't know where to jump on that symbol, it would move the cursor to the beginning of the outer pair of matching items (opening parenthesis in this case) - before the cursor's last position, which leads tosearchpos
finding the same match again, creating an infinite loop.The fix is to check whether the
%
has moved the cursor backwards and return it to its last position, so that thesearchpos
would find a next match (matching at cursor position is not set ina:flags2
).The iteration count check is not necessary, but it takes around 30 seconds for it to return an error on my laptop for the example above, and would prevent Vim from completely freezing if something else causes the loop to never exit.