Skip to content

Fix off by one selection of extract variable/method #957

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

Merged

Conversation

lieryan
Copy link
Contributor

@lieryan lieryan commented Nov 6, 2018

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":

test("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:

[Pymode]: error: Extracted piece should contain complete statements.

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 using di(, no additional l).

This PR changes the offset calculation to be more typical to normal Vim behaviour. With the change in this PR, selecting "hello world" with vi( and then calling pymode#rope#extract_variable() with <C-c>rl should give you the "Extract variable" prompt:

[Pymode]  Extract variable. 
[Pymode] New variable name: > 

@diraol
Copy link
Contributor

diraol commented Dec 31, 2018

Hi @lieryan sorry for taking so long to answer.

Can you provide a sample/gist with clear instructions on how to test the current behavior and the expected behavior that should happen with your patch?

Including some sample code to test the commands against.

Thanks!

@lieryan
Copy link
Contributor Author

lieryan commented Dec 31, 2018

@diraol Thanks for looking at the PR. I had updated the original text with some examples and (hopefully) clearer instruction. Let me know if there is anything else I can elaborate further.

@diraol
Copy link
Contributor

diraol commented Jan 5, 2019

Thanks @lieryan ! I've made the tests and was able to see your PR working! ;) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants