rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 302 forks source link

Remember cursor position when switching modules #4700

Open Gener4tor opened 5 years ago

Gener4tor commented 5 years ago

The built-in-Explorer of VBE opens modules at the position they are open:

This is IMHO the way it should work.

The Code Explorer from rubberduck opens modules always with the cursor on top - whereever it was before. This is very annoying because you have to scroll down and search the position where have been before basicly every time you open a module with the code explorer...

Inarion commented 5 years ago

Situational workaround: When having jumped to a declaration with Shift+F2 you can then jump to your previous position with Ctrl+Shift+F2, even across modules. (I'm not totally clear what positions it will jump back to when triggered repeatedly, though.)

That aside, I totally agree. Preserving the (vertical)* cursor positions is something the VBE's project explorer natively does.

* Actually the VBE remembers the horizontal position within the line as well, but I'm not sure that's totally necessary. But it likely wouldn't hurt to have it. :)

bclothier commented 5 years ago

I'd be looking at this line:

https://github.com/rubberduck-vba/Rubberduck/blob/90e14a977cfbe72ce70f50290457db5d925d696d/Rubberduck.Core/UI/CodeExplorer/Commands/OpenCommand.cs#L25

Most likely the the selection is L1C1 when it should be whatever it is originally.

retailcoder commented 5 years ago

@bclothier that's right - the QMN+Selection for a module (i.e. QualifiedSelection) is always L1C1. To fix it we need to split that instruction and evaluate whether we're looking at a module or a member; if a member, GetNavigationArgs is fine. Otherwise, we need to create a NavigationArgs off the current selection in that module.