terryma / vim-expand-region

Vim plugin that allows you to visually select increasingly larger regions of text using the same key combination.
MIT License
1.1k stars 46 forks source link

Should check whether new region includes cursor position #2

Closed majutsushi closed 11 years ago

majutsushi commented 11 years ago

I noticed that some text objects can select unexpected regions. For example, put the following into a file:

index(list, '(')
empty(taginfo)

then put the cursor on top of empty and press vib. The parentheses on the first line should now be selected. This is obviously not useful for our case. So it would make sense to check whether the region candidates actually include the original cursor position before trying to use them.

terryma commented 11 years ago

Thanks for reporting this! During testing, I discovered that i' and i" can cause a region to be highlighted after the cursor position. Never realized that it's possible for it to jump to before the cursor as well! The update performs a boundary box check now instead of just handling one of the two cases. Let me know if you continue to see this problem.

majutsushi commented 11 years ago

Works great now, thanks! By the way, I noticed that you could simplify the compare_pos() function by just returning the result of the subtraction instead of using ternary operators and the additional if clause, since you're only interested in positive, equal or negative anyway.

terryma commented 11 years ago

Acknowledged. I didn't want to deal with the potential overflow issues, although in this particular case, the file has to be huuuuge for overflow to even become an issue. I guess I'm just paranoid. :)

terryma commented 11 years ago

Nvm, on second thought, that scenario isn't possible. You're right, pushing a quick fix. Thanks!