Fix off by one selection of extract variable/method #957
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.
Currently, extract variable and method uses the left side of the visual selection cursor to select range for both sides of the visual selection cursors. This is an incorrect selection behaviour and is inconsistent with how vim normally select texts, which is to use the left side of the left selection cursor but the right side of the right selection cursor. For example, suppose that you have a file with this code, and you place your cursor anywhere in the middle of the text "hello world":
Currently, the more intuitive
vi(<C-c>rl
will visually select the text range"hello world"
and essentially do a:call pymode#rope#extract_variable()
. However, this currently would produce this error:As a workaround, you can do
vi(l<C-c>rl
to select"hello world")
instead, but this is inconsistent with how Vim text object selection normally works and it takes an extra keystroke (for example, if you want to delete "hello cursor there" you simply do it usingdi(
, no additionall
).This PR changes the offset calculation to be more typical to normal Vim behaviour. With the change in this PR, selecting
"hello world"
withvi(
and then callingpymode#rope#extract_variable()
with<C-c>rl
should give you the "Extract variable" prompt: