You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot right click on command palette-like panels #153267
bugIssue identified by VS Code Team member as probable buginsiders-releasedPatch has been released in VS Code InsidersmenusMenu items and widget issuesquick-pickQuick-pick widget issuesverifiedVerification succeeded
Thanks for reporting this issue! Unfortunately, it's hard for us to understand what issue you're seeing. Please help us out by providing a screen recording showing exactly what isn't working as expected. While we can work with most standard formats, .gif files are preferred as they are displayed inline on GitHub. You may find https://gifcap.dev helpful as a browser-based gif recording tool.
If the issue depends on keyboard input, you can help us by enabling screencast mode for the recording (Developer: Toggle Screencast Mode in the command palette).
SteVen Batten (@sbatten) I can't repro this on macOS with native context menus. I have a feeling the command palette is losing focus and hiding which is expected behavior... but I don't think the focus should be lost. Any thoughts?
this was the last time we took a look at this behavior. #58164
but your analysis is correct that focus is lost. quick picks could use the input box as the parent container to avoid the focus lost. the context view service has the API for this.
Hey guys, seems this "focus loss on context menu" has more than one place to occur.
There was another similar issue I created long ago (#130564). The issue was within the file explorer. João Moreno (@joaomoreno) took the issue and fixed it with #169931
Note that if this issue has the same root as that one, it will hardly happen on macOS for its natural restriction on "native". And it is annoying everywhere else including web.
Pleaase check it out as that fix might give you a clue on how to fix this, or if they really share common root then you may also write a common fix. (please try not to break the other one, it took nearly 4 years to be noticed and be fixed)
Sharing media and context from merged PR #344806 for verification:
🤖
Problem
With HTML (custom) context menus, right-clicking the Command Palette or any quick pick dismisses it as soon as the menu appears. Custom menus are always used on web, and on desktop by default with the custom title bar. The menu takes DOM focus into a context view outside .quick-input-widget, so the quick input's focus tracker sees a blur and hides. #155546 only changed the z-index. Native macOS menus never move DOM focus, so they were not affected.
Hosting the menu inside its owner (domForShadowRoot) keeps focus in the owner, but then the owner's overflow: hidden and transforms clip the menu. That is why earlier revisions of this PR needed animation and will-change workarounds, and why item-row menus could not be fixed at all.
Change: an opt-in popover mode in ContextView
The creator of a context view still passes its owner explicitly, as before. It can now also ask for the view to be hosted as a popover there (IContextMenuDelegate.hostAsPopover / IContextViewDelegate.hostAsPopover). The view's DOM is a popover="manual" element (optionally with a shadow root) inside the owner, so:
focus stays inside the owner, and the owner's focus tracker never sees a blur;
the menu renders in the top layer, unclipped by the owner's overflow or transforms.
All popover behaviour lives in ContextView (base/browser/ui/contextview/contextview.ts):
showPopover() with fallback: if it throws (e.g. the owner is disconnected or popovers are unsupported), the error is reported and the view falls back to the existing fixed position in the owner window's container;
focus restore on hide to the element focused before showing, but only if focus is still in the view or on the body, which popovers don't do themselves;
key isolation: key events in the view don't reach the owner or window keybindings;
dismissal on a pointer press outside the view and its owner;
dismissal when the owner is removed or hidden.
ContextMenuHandler skips its mouse blocker and its own focus return when the view is actually hosted as a popover, and keeps both on fallback. Nothing changes for existing callers that don't opt in.
Opt-ins (all pass the owner explicitly, no DOM discovery):
Quick input toolbars (title left/right, inline, and item rows): renderDropdownAsPopover → menuAsPopover → hostAsPopover, hosted at the dropdown element.
Text input context menu (TextInputActionsProvider, workbench): hosted as a popover at the right-clicked input's parent. This fixes the quick input's own input box and any other input with the same problem (e.g. the icon picker search box, whose grid refocuses itself on blur) without widget-specific code. Ordinary inputs look and behave the same.
Removed compared with the previous head (8aa28cc): quick input's own input context menu, finishOpenMotion and its listeners (including Shift+F10), the hosted outside-click and key handling, the inQuickInput clearing, the quickInput.css animation and will-change changes, the icon picker and terminal find widget changes, and the move of createTextInputActions to platform. Kept: Paste ignores an empty readText(), because the browser clipboard service returns '' on failure, which used to replace the selection with nothing. One fix in QuickInputController.hide(): when deciding whether to restore focus, check the document's active element rather than the deep one, because focus in a hosted shadow-root menu is inside the container.
Shared focus check: getFocusedContextView / isContextViewFocused (contextview.ts) look at the deep active element, so callers that ask "is a context menu focused?" also see a menu hosted in a shadow root. Settings editor, notebook cell list and the inline edit input box use it instead of their own activeElement + .context-view checks (settings also defers its refresh against the focused menu rather than the first .context-view in the document). When the popover is inside an owner's shadow root, a small reset stylesheet is added to that root so the user agent [popover] styles don't affect the view.
Note: the design changed substantially after the earlier approval on 8aa28cc. Please re-review.
Tests
src/vs/base/test/browser/ui/contextview/contextview.test.ts, "popover hosting" suite (17 tests): top-layer hosting in light DOM and in a shadow root; fallback when showPopover throws (before rendering, without moving focus) and when the owner is disconnected; focus restore and not stealing focus back; legacy positions unchanged; outside pointer dismissal; key isolation; owner removed or hidden, with and without layout; zero-size owner stays open; switching between popover and legacy hosting; close animation; dispose.
src/vs/platform/contextview/test/browser/contextMenuHandler.test.ts: no mouse blocker or focus return when hosted; both kept on fallback and for legacy menus.
src/vs/workbench/test/browser/contextViewService.test.ts: popover only when the delegate opts in; fallback to the owner window's layout container.
src/vs/workbench/test/browser/actions/textInputActions.test.ts: the menu is hosted at the right-clicked input's parent; non-inputs and prevented events are ignored; ordinary inputs leave nothing behind; Paste replaces the selection, and keeps it on an empty or unreadable clipboard.
src/vs/platform/quickinput/test/electron-browser/quickInputFocusOut.test.ts (real document focus, real ContextViewService/ContextMenuService/Menu/TextInputActionsProvider, 18 tests): one hosted menu; Escape, actions, Paste failure; keys don't reach the quick input or window keybindings while inQuickInput keeps its meaning; toolbar menus and arrow keys; pointer presses on the menu part outside the picker vs. on the picker; a submenu outside both is hittable and runs; window blur; focus loss without a menu; hide closes hosted menus and the next picker opens cleanly; unrelated menus; ignoreFocusOut; ordinary inputs; item-row overflow menus hosted with every item hittable (previously unfixable); the icon picker's nested focus owner.
./scripts/test.sh --run on these suites plus iconPicker.test.ts and frostedGlass.test.ts: 138 passing. npm run eslint, tsc -p src/tsconfig.json --noEmit, npm run valid-layers-check: clean.
bugIssue identified by VS Code Team member as probable buginsiders-releasedPatch has been released in VS Code InsidersmenusMenu items and widget issuesquick-pickQuick-pick widget issuesverifiedVerification succeeded
Activity
bpasero commentedon Jun 27, 2022
/gifPlease
vscodenpa commentedon Jun 27, 2022
Thanks for reporting this issue! Unfortunately, it's hard for us to understand what issue you're seeing. Please help us out by providing a screen recording showing exactly what isn't working as expected. While we can work with most standard formats,
.giffiles are preferred as they are displayed inline on GitHub. You may find https://gifcap.dev helpful as a browser-based gif recording tool.If the issue depends on keyboard input, you can help us by enabling screencast mode for the recording (
Developer: Toggle Screencast Modein the command palette).Happy coding!
infinnie commentedon Jun 28, 2022
done
TylerLeonhardt commentedon Jun 28, 2022
SteVen Batten (@sbatten) I can't repro this on macOS with native context menus. I have a feeling the command palette is losing focus and hiding which is expected behavior... but I don't think the focus should be lost. Any thoughts?
sbatten commentedon Jun 28, 2022
this was the last time we took a look at this behavior. #58164
but your analysis is correct that focus is lost. quick picks could use the input box as the parent container to avoid the focus lost. the context view service has the API for this.
7 remaining items
a-stewart commentedon Sep 26, 2022
I see the same issue on VS Code web (insiders), on both Linux and Mac OS.
Both work fine with VS Code running natively, but on the web version a right click looses context.
yilmazdurmaz commentedon Sep 6, 2023
Hey guys, seems this "focus loss on context menu" has more than one place to occur.
There was another similar issue I created long ago (#130564). The issue was within the file explorer. João Moreno (@joaomoreno) took the issue and fixed it with #169931
Note that if this issue has the same root as that one, it will hardly happen on macOS for its natural restriction on "native". And it is annoying everywhere else including web.
Pleaase check it out as that fix might give you a clue on how to fix this, or if they really share common root then you may also write a common fix. (please try not to break the other one, it took nearly 4 years to be noticed and be fixed)
fgt1t5y commentedon Dec 26, 2024
So it's a hard problem to fix?
quickinput: host context menus inside the quick input
Host quick input menus as Context View popovers
Keep quick input open while its context menu has focus (#344806)
vs-code-engineering commentedon Oct 30, 2026
Sharing media and context from merged PR #344806 for verification:
🤖
Problem
With HTML (custom) context menus, right-clicking the Command Palette or any quick pick dismisses it as soon as the menu appears. Custom menus are always used on web, and on desktop by default with the custom title bar. The menu takes DOM focus into a context view outside
.quick-input-widget, so the quick input's focus tracker sees a blur and hides. #155546 only changed the z-index. Native macOS menus never move DOM focus, so they were not affected.Hosting the menu inside its owner (
domForShadowRoot) keeps focus in the owner, but then the owner'soverflow: hiddenand transforms clip the menu. That is why earlier revisions of this PR needed animation andwill-changeworkarounds, and why item-row menus could not be fixed at all.Change: an opt-in popover mode in ContextView
The creator of a context view still passes its owner explicitly, as before. It can now also ask for the view to be hosted as a popover there (
IContextMenuDelegate.hostAsPopover/IContextViewDelegate.hostAsPopover). The view's DOM is apopover="manual"element (optionally with a shadow root) inside the owner, so:All popover behaviour lives in
ContextView(base/browser/ui/contextview/contextview.ts):showPopover()with fallback: if it throws (e.g. the owner is disconnected or popovers are unsupported), the error is reported and the view falls back to the existing fixed position in the owner window's container;ContextMenuHandlerskips its mouse blocker and its own focus return when the view is actually hosted as a popover, and keeps both on fallback. Nothing changes for existing callers that don't opt in.Opt-ins (all pass the owner explicitly, no DOM discovery):
renderDropdownAsPopover→menuAsPopover→hostAsPopover, hosted at the dropdown element.TextInputActionsProvider, workbench): hosted as a popover at the right-clicked input's parent. This fixes the quick input's own input box and any other input with the same problem (e.g. the icon picker search box, whose grid refocuses itself on blur) without widget-specific code. Ordinary inputs look and behave the same.Removed compared with the previous head (8aa28cc): quick input's own input context menu,
finishOpenMotionand its listeners (including Shift+F10), the hosted outside-click and key handling, theinQuickInputclearing, thequickInput.cssanimation andwill-changechanges, the icon picker and terminal find widget changes, and the move ofcreateTextInputActionsto platform. Kept: Paste ignores an emptyreadText(), because the browser clipboard service returns''on failure, which used to replace the selection with nothing. One fix inQuickInputController.hide(): when deciding whether to restore focus, check the document's active element rather than the deep one, because focus in a hosted shadow-root menu is inside the container.Shared focus check:
getFocusedContextView/isContextViewFocused(contextview.ts) look at the deep active element, so callers that ask "is a context menu focused?" also see a menu hosted in a shadow root. Settings editor, notebook cell list and the inline edit input box use it instead of their ownactiveElement+.context-viewchecks (settings also defers its refresh against the focused menu rather than the first.context-viewin the document). When the popover is inside an owner's shadow root, a small reset stylesheet is added to that root so the user agent[popover]styles don't affect the view.Tests
src/vs/base/test/browser/ui/contextview/contextview.test.ts, "popover hosting" suite (17 tests): top-layer hosting in light DOM and in a shadow root; fallback whenshowPopoverthrows (before rendering, without moving focus) and when the owner is disconnected; focus restore and not stealing focus back; legacy positions unchanged; outside pointer dismissal; key isolation; owner removed or hidden, with and without layout; zero-size owner stays open; switching between popover and legacy hosting; close animation; dispose.src/vs/platform/contextview/test/browser/contextMenuHandler.test.ts: no mouse blocker or focus return when hosted; both kept on fallback and for legacy menus.src/vs/workbench/test/browser/contextViewService.test.ts: popover only when the delegate opts in; fallback to the owner window's layout container.src/vs/workbench/test/browser/actions/textInputActions.test.ts: the menu is hosted at the right-clicked input's parent; non-inputs and prevented events are ignored; ordinary inputs leave nothing behind; Paste replaces the selection, and keeps it on an empty or unreadable clipboard.src/vs/platform/quickinput/test/electron-browser/quickInputFocusOut.test.ts(real document focus, realContextViewService/ContextMenuService/Menu/TextInputActionsProvider, 18 tests): one hosted menu; Escape, actions, Paste failure; keys don't reach the quick input or window keybindings whileinQuickInputkeeps its meaning; toolbar menus and arrow keys; pointer presses on the menu part outside the picker vs. on the picker; a submenu outside both is hittable and runs; window blur; focus loss without a menu; hide closes hosted menus and the next picker opens cleanly; unrelated menus;ignoreFocusOut; ordinary inputs; item-row overflow menus hosted with every item hittable (previously unfixable); the icon picker's nested focus owner../scripts/test.sh --runon these suites plusiconPicker.test.tsandfrostedGlass.test.ts: 138 passing.npm run eslint,tsc -p src/tsconfig.json --noEmit,npm run valid-layers-check: clean.Screenshot Changes
Base:
d3fce61aCurrent:9a8b17cbChanged (1)
chat/aiCustomizations/customizationMigrationDashboard/MigrationsTooltip/LightScreenshot report: #344806 (comment)
Source PR: #344806