Moving variable to field - cursor position after the operation

Answered

When I am moving / crating a field variable, the cursor afterwards stays with the declaration of the field variable on the top.
This really annoys me, becaue I have to manually go back to the point where I was before creating / moving the local variable to a field.

As far as I observed, this does not happen in Eclipse, but probably I am not aware of some settings in IntelliJ to "return to the code after variable declaration"

I hope I am clear describing my problem.

Thanks in advance in pointing out the solution.

14 comments
Comment actions Permalink

Could you please provide a short video to illustrate it? I can't reproduce it with the Introduce Field refactoring. What IDEA version do you use?

0
Comment actions Permalink

IntelliJ IDEA 2016.1
Build #IU-145.258, built on March 17, 2016
JRE: 1.8.0_60-b27 x86
JVM: Java HotSpot(TM) Server VM by Oracle Corporation

I'll attach video later on, probably today. Thanks

0
Comment actions Permalink

I have prepared a video, how can I upload it here? Seems there is no way... It is 184 kB packed with 7zip.



0
Comment actions Permalink

Thanks Serge, I have used that way to upload : https://uploads.jetbrains.com/

The file name is

field.7z (184 kb) 100%

0
Comment actions Permalink

Please use Refactor | Extract | Field... instead (Ctrl+Alt+F).

0
Comment actions Permalink

This is such a bad alternative.

1) It doesn't show up in the quick solutions menu

2) It does not use the instance variable name I already typed.

e.g. this.name = name; (press ctrl+alt+f) it changes the code to "string = name"

3) I don't want to remember shortcuts for such specific things. The generic solutions menu should be enough. Otherwise I'd have to remember 20 shortcuts solely for all the different code completion/ solutions.

 

Did anyone find a better solution in the meantime?

0
Comment actions Permalink

Did you try Refactor | Refactor This? Should be easier to rememeber.

0
Comment actions Permalink

That's just another menu where I could select Extract Field, so takes even more time and still has no benefit comparing to using the "create field" function.

I don't know why you are looking for workaround. It's pretty clear that the "Create field" function in the quick solution menu is the one intended to do this task. It's just missing the tiny feature that the cursor will return to the original edit position after the field was created.

0
Comment actions Permalink

Hi Julian,
Thanks for suggestion! We've discussed a similar case in the past IDEABKL-7836. I've added more information on how to improve that. To speed up the implementation you may vote up to the feature on YouTrack.

For now, you may use refactoring settings to keep the cursor in the same position.

1
Comment actions Permalink

Hmm the ticket on youtrack doesn't sound like it's the same. When I create an instance field the cursor actually does go there, but not back after creating it.

However I found a workaround with navigate back which is enough for this. It would be nicer if intellij jumped back automatically but it also works good like this.

0
Comment actions Permalink

Yes, initially there was a bit different discussion int the ticket but the main point in both cases - make the creation of the fields via intention action menu more comfortable.

> It would be nicer if intellij jumped back automatically

Yes, I added more information about that to the ticket.

1

Please sign in to leave a comment.