Vscode: Multi monitors: `code -n` doesn't focus on the new window that opens

Created on 30 May 2018  Â·  20Comments  Â·  Source: microsoft/vscode

Running code -n refocuses on the already open window.

It would make more sense for it to focus on the new window. This might just be an issue with how MacOS deals with new windows, I'm not able to test on Windows at the moment.

  • VSCode Version: 1.23.1
  • OS Version: MacOS 10.13.4

Steps to Reproduce:

  1. Open a Code window
  2. Run code -n


Does this issue occur when all extensions are disabled?: Yes

*out-of-scope electron help wanted mac upstream

Most helpful comment

@bpasero

  • Have Code open on macOS screen (Main)
  • Open iTerm on external monitor's screen (External)
  • code -n
  • A new Code window is open at External
  • Focus is back to Code in Main

All 20 comments

  -n, --new-window                   Force to open a new window.
  -r, --reuse-window                 Force to open a file or folder in the last active window.

Maybe you should use -r instead of -n, if that's your intended behavior.

I think you're misunderstanding. I want to focus on the newly opened window so I can start typing in it immediately.

I see what you mean. Having Code Window A and running code -n to open Code Window B will not focus on the editor of B. Instead focus is given to A.

I can reproduce this.

@octref @Clockwork757 you can reproduce this? I would like too, but cannot. Here is what I do:

  • start code once
  • open a terminal outside of code
  • type "code -n"
  • a new empty window opens and has focus

What are you doing differently?

@bpasero

  • Have Code open on macOS screen (Main)
  • Open iTerm on external monitor's screen (External)
  • code -n
  • A new Code window is open at External
  • Focus is back to Code in Main

I have no idea when this broke or why this happens. If someone wants to chime in, feel free.

I wonder if this could possibly be related to macOS 10.13.4 update that came in recently. I can reproduce this behaviour in VS Code back to version 1.20, so I doubt this is a change we did that could explain this.

If anyone with a macOS version < 10.13.4 could try to reproduce this:

  • connect an external monitor
  • start VSCode
  • open a terminal
  • type code -n
  • is the new window getting focus or the old window?

Happens to me on 10.12.6.

Crazy... why did no-one report this before :-?

If someone wants to chime in and/or has an idea, feel free. Things I found out so far:

  • it seems to reproduce for a very long time
  • it only reproduces for me when the window is on a different display compared to the monitor that is used for opening the new window
  • it is NOT enough to just focus() the new window that is opening, the other one is still getting focus

This could be an upstream/electron issue, not sure yet.

I suspect this is a MacOS problem. I reproduced the same behavior with Chrome.

Sidenote: sorry for the closing and reopening. I think I'm instinctively hitting that as a cancel button😓

Interesting, I could not reproduce it with another app, but I also did not try Chrome, so it maybe related to Electron/Chrome.

I can definitely reproduce this reliably and it is only VSCode that has this issue. Chrome definitely does not.

also its worth noting that this is not a -n specific issue. it also fails to focus the new window when opening a director as a project by executing code ./some-directory

ive come across another side effect of this same issue.
https://github.com/microsoft/vscode/issues/80314
Any instance of a vscode window with a given directory open in it will take focus, regardless of the flags provided when attempting to open another window. in short, if you try to open dir foo twice but use the -n flag it wont even open a new window. also if you try to just open a second window it works fine if the window does not take a path as an argument, but even then trying to open the same dir foo in the newly opened window refocuses the old window.

@bpasero this shouldnt be an issue, because even though the shell prompt has a built in command for this, the documentation for the 'code' command makes it seem as though it can perform the required actions. however it doesnt. so either it should be included in the documentation or it should be changed to accommodate behavior.

thanks for pointing out the the duplicate command though. still would like to see this sort of thing resolved.

Feel free to provide a PR to change the documentation of the CLI program.

I still have this problem:

I open two projects all pointing to their own different directories.
I use the subl command to open a file within one of those directories.
It opens that file in whatever project window was last focused.
It should open each file in their corresponding project directory.

Should I open a new issue?

Thanks!

On Wed, Sep 4, 2019 at 8:02 AM Benjamin Pasero notifications@github.com
wrote:

Feel free to provide a PR to change the documentation of the CLI program.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/vscode/issues/50793?email_source=notifications&email_token=AAACBQJCBIHSUD4ZJUXTDX3QH7EXHA5CNFSM4FCNN6M2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD533YYY#issuecomment-527940707,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAACBQOTGOU6ZSIHZ2BRZX3QH7EXHANCNFSM4FCNN6MQ
.

--
Jared

This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding and happy coding!

Was this page helpful?
0 / 5 - 0 ratings