vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Switch first and second result in quickOpen if first result is the current editor

Open jacekkopecky opened this issue 3 years ago • 7 comments

Fixes #159299

This code intercepts quick-open pick lists and if the first pick is the same file as the current editor, it switches the first two results.

It's my first attempt to contribute to VSCode therefore it's more of an RFC, I guess. 8-)

To test this, go to quick open (ctrl-p or cmd-p), type something to find a file, open that file, then go to quick open, type the same something as before, and the same file shouldn't be the first pick this time.

jacekkopecky avatar Aug 26 '22 13:08 jacekkopecky

CLA assistant check
All CLA requirements met.

ghost avatar Aug 26 '22 13:08 ghost

Another benefit of this reordering is that a quick cmd-p enter sequence takes you to the previous editor.

jacekkopecky avatar Aug 26 '22 13:08 jacekkopecky

Another benefit of this reordering is that a quick cmd-p enter sequence takes you to the previous editor.

The disadvantage of course is that cmd-p cmd-p does not take you to the previous editor anymore which is the current behaviour.

nikita-r avatar Aug 26 '22 13:08 nikita-r

Quite right @nikita-r; I didn't know you could navigate in that list with cmd-p. As I don't use it, I need to learn more about that pattern of use: do you use the second cmd-p also after typing a query, or only when the first cmd-p already shows what you want?

jacekkopecky avatar Aug 26 '22 14:08 jacekkopecky

I don't really know how I use it TBH :) the secondary purpose of cmd-p is somewhat unexpected probably, but some people may be used to it by now...

I have read the issue though and I have a comment on it: consider Angular projects where there are three "paired" files: ProductList.component.html, ProductList.component.ts, ProductList.component.scss. Now, following the issue logic, you'd want the current file to be the third instead of the second. Hard to come up with a definitive logic here consistent with the Principle of Least Surprise.

nikita-r avatar Aug 26 '22 15:08 nikita-r

Again good point @nikita-r !

I think if you have multiple files, you would subconsciously expect to have to look in the list (not expect there to be one obviously right answer), or you'd add a distinguisher in the query. I could imagine if I worked with angular I'd learn to just type ht/ts/cs to the end of the query (e.g. plistht) to get where I want. But it feels entirely unnecessary when it's simply the other matching file.

I consider it very unlikely that the user would want to go to the file they're already in. I feel that when typing that quick open query, I'm specifying the file I want among the other files. Maybe the switching behaviour could be triggered by a non-empty query, and even controlled by settings.

In Atom, when I needed this years ago, I ended up making an extension that tweaked the default behavior of the editor. I think VSCode extensions are more constrained (not that that's necessarily a bad thing) so I don't think the same approach is available here.

jacekkopecky avatar Aug 26 '22 17:08 jacekkopecky

I have rebased the branch. The rationale stands: when using the "go to file" picker, when I have typed something to search, I'm unlikely to want to go to the active file, therefore it shouldn't be the first result.

This PR switches the first and second results if the first result is the active file.

jacekkopecky avatar Feb 18 '24 11:02 jacekkopecky