Switch first and second result in quickOpen if first result is the current editor
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.
Another benefit of this reordering is that a quick cmd-p enter sequence takes you to the previous editor.
Another benefit of this reordering is that a quick
cmd-p entersequence 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.
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?
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.
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.
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.