vscode: Opening file with source:line breaks Cmd+D "Add Next Occurance"

  • VSCode Version: 1.37.1
  • OS Version: Mac 10.12.6

Issue

Here’s a weird one for you! This is 100% reproducible, and only appeared recently.

Whenever I open Visual Studio Code using line numbers (from iTerm2 shortcut or others), the Cmd+D shortcut key to select other instances doesn’t work until the VSCode window loses and regains focus.

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

Steps to Reproduce:

Part 1

  1. Have iTerm2
  2. Cmd + Click on a file name
  3. Once VSCode opens, Cmd+D on some text that should have another match
  4. Notice that the “Selection” menu item at the top flashes as activated, but no new matching selections are selected

Part 2

  1. Click around in VSCode, in the same editor, other editors, etc.
  2. Press Cmd+D
  3. Notice that the “Selection” menu item at the top flashes as activated, but no new matching selections are selected

Part 3

  1. Cmd+Tab to another window
  2. Cmd+Tab back to VSCode
  3. Notice that the Cmd+D key shortcut is now working as expected.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 29 (19 by maintainers)

Commits related to this issue

Most upvoted comments

@alexandrudima oh, now that I actually look into the menu code, this seems very fishy:

// We make sure to not run actions when the window has no focus, this helps
// for https://github.com/Microsoft/vscode/issues/25907 and specifically for
// https://github.com/Microsoft/vscode/issues/11928
// Still allow to run when the last active window is minimized though for
// https://github.com/Microsoft/vscode/issues/63000
let activeWindow = this.windowsMainService.getFocusedWindow();
if (!activeWindow) {
	const lastActiveWindow = this.windowsMainService.getLastActiveWindow();
	if (lastActiveWindow && lastActiveWindow.isMinimized()) {
		activeWindow = lastActiveWindow;
	}
}

@sbatten it looks like we fail to send the action to the last active window at least? any particular reason?

E.g. when you check the implementation of sendToFocused it will do this:

const focusedWindow = this.getFocusedWindow() || this.getLastActiveWindow();

I wonder if we should change IWindowsService#getFocusedWindow to do that so that we always have a window.