Skip to content

Cannot right click on command palette-like panels #153267

Closed

Description

@infinnie

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

  • VS Code Version: 1.68.1
  • OS Version: Windows 7

Steps to Reproduce:

  1. Open Command Palette, the Git branch selection panel, or a similar panel.
  2. Right click on the panel, say in order to try and paste something.
  3. The panel is closed at the same time the context menu is shown.

command-palette.mp4

Screen recording in 1.69.0 Insiders

Activity

  1. bpasero commented on Jun 27, 2022

    @bpasero
    Contributor

    /gifPlease

  2. vscodenpa commented on Jun 27, 2022

    @vscodenpa

    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).

    Happy coding!

  3. added
    info-needed
    on Jun 27, 2022
  4. infinnie commented on Jun 28, 2022

    @infinnie
    ContributorAuthor

    /gifPlease

    done

  5. TylerLeonhardt commented on Jun 28, 2022

    @TylerLeonhardt
    Member

    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?

  6. sbatten commented on Jun 28, 2022

    @sbatten
    Member

    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. removed
    info-needed
    on Jun 28, 2022
  8. 7 remaining items

  9. a-stewart commented on Sep 26, 2022

    @a-stewart
    Contributor

    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.

  10. yilmazdurmaz commented on Sep 6, 2023

    @yilmazdurmaz

    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)

  11. fgt1t5y commented on Dec 26, 2024

    @fgt1t5y

    So it's a hard problem to fix?

  12. added 3 commits that reference this issue on Oct 28, 2026
    3d4cc55
    b64fc9a
    f7c0389
  13. added
    unreleased
    on Oct 30, 2026
  14. vs-code-engineering commented on Oct 30, 2026

    @vs-code-engineering
    Contributor

    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.

    Screenshot Changes

    Base: d3fce61a Current: 9a8b17cb

    Changed (1)

    chat/aiCustomizations/customizationMigrationDashboard/MigrationsTooltip/Light
    Before After
    before after

    Screenshot report: #344806 (comment)

    Source PR: #344806

  15. added
    insiders-released
    and removed
    unreleased
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buginsiders-releasedmenusquick-pickverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions