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
Keep quick input open while its context menu has focus - #344806
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.
Right-clicking the quick input with HTML context menus moved focus into
the context view, which the focus tracker treated as a blur and hid the
picker. Defer the focus-out decision while focus is inside a context
view and reconcile once focus leaves it, after the menu has restored
focus. Genuine outside clicks and focus loss still hide the picker.
Fixes#153267
Co-authored-by: Copilot <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Focus handling leaves quick-input keybindings active while a menu owns focus, allowing unintended command execution, and can leave the picker open when its window loses focus.
Replace the deferred focus-out handling with hosting: the quick input now
shows the text input context menu itself (when the host provides the
actions) and renders it, as well as its title and inline toolbar
dropdowns, inside its own DOM so focus never leaves the widget.
- add an optional `textInputContextMenuActions` quick input option, wired
by the workbench quick input service to the standard text input actions
- finish the opening motion before a menu opens and stop the motion from
leaving a transform / will-change behind, which would otherwise clip
the fixed positioned menu inside the widget with Modern UI
- close a context view hosted inside the quick input when it hides
Fixes#153267
Co-authored-by: Copilot <[email protected]>
A context menu hosted inside the quick input blocks mouse interaction
with the rest of the UI, so clicking outside of it only closed the menu
and kept focus within the quick input. Treat a mouse down on the hosted
context view outside of both the menu and the quick input like focus
moving out of the quick input.
Co-authored-by: Copilot <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Left/Right keys in the More menu can bubble to the enclosing toolbar, move focus, and dismiss the menu; event propagation needs to be stopped before reaching the toolbar, with regression coverage for mixed primary and secondary buttons.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Prevent More menu arrow keys from bubbling to the ActionBar
With both primary and secondary toolbar buttons, pressing Left/Right in the hosted More menu reaches the enclosing horizontal ActionBar before this listener, moving focus to an underlying button and dismissing the menu (actionbar.ts:161–164). Stop bubbling on the context-view element itself, after the menu's handlers but before the toolbar, and restrict this to events whose path includes this picker. Add a regression test for arrow keys with mixed primary/secondary buttons.
🤖 Re: Copilot review on 0b3ad79, "Prevent More menu arrow keys from bubbling to the ActionBar" (summary-only finding, no inline thread): valid, fixed in 217ea00. Key events of a context view hosted inside this quick input now stop on the context view element itself, after the menu's own handlers and before the enclosing toolbar ActionBar (and the quick input / keybindings), and only when the shared context view is hosted in this picker. Added a regression test with mixed primary and secondary title buttons asserting ArrowLeft/ArrowRight/Home/End keep the hosted menu open with focus in it (fails without the fix).
Replace the quick-input-specific `textInputContextMenuActions` option with a
generic, owner-declared context menu host: context menus without an explicit
`domForShadowRoot` that are triggered from within an element declared with
`markAsContextMenuHost` render inside the nearest such host. The quick input
declares its widget (and no longer opens the text input menu itself), and the
icon picker declares its icon grid, which owns focus within the picker.
Co-authored-by: Copilot <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Clicks on overflowing hosted submenu items can dismiss the picker before their actions run, requiring dismissal to be limited to the mouse blocker and a regression test.
Move the ContextView popover reset to `[popover]` rules in contextview.css,
so removing the popover attribute also removes the reset. Covers the styles
while rendering, before layout adds the `fixed` class.
Co-authored-by: Copilot <[email protected]>
- Keep a view shown while restoring focus on hide (e.g. an input box
message) instead of hiding and detaching it, and stop owner tracking
before restoring focus
- Detect focus inside shadow root hosted context views for inline
editing, the settings editor and notebook focus checks
- Hide popovers when an owner without size is removed or hidden
- Report popovers dismissed by the context view itself as cancelled
- Hide a dropdown's popover menu when its label is pressed again
Co-authored-by: Copilot <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved menu-handling issues can leave the settings tree stale after a shadow-hosted menu closes and misassign menu ownership when an empty request follows an open menu.
… for shadow-hosted menus
- ContextMenuService records the shown delegate only once its actions are
non-empty, so an empty request no longer takes ownership of a visible menu.
- Add getFocusedContextView, which finds the focused context view across a
shadow root, and use it in the settings editor to schedule the deferred
tree refresh instead of a light-DOM querySelector.
Co-authored-by: Copilot <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
What is this case? When a menu is shown from a dropdown, you can't click the dropdown button again because the context view blocker. So any attempt to click will already result in a hide of the context menu, correct? Did hideContextMenu get added to the delegate just for this?
The reason will be displayed to describe this comment to others. Learn more.
🤖 Good question — yes, hideContextMenu exists only for this case, and your reasoning holds for regular (fixed) menus: the .context-view-block eats the mousedown, the menu blurs and closes.
The difference is popover-hosted dropdowns (renderDropdownAsPopover, opted in by this PR for the quick input title/inline/row toolbars). Those intentionally have no block so the quick input keeps focus and stays open. ContextView's popover pointer-down dismissal excludes presses on the owner (the dropdown element) — otherwise the same click would close the menu on pointerdown and reopen it on click. So a second label press reached BaseDropdown, which only flipped its own state and left the menu open; the hook lets it close the menu.
Honest reachability check: the only way a popover DropdownMenu appears in those toolbars is a secondary: trueIQuickInputButton (supported since #285214). I found no current caller in core and it isn't exposed in the extension API, so this is latent today. In f8bee5b I cut it to the minimum: an optional no-arg IContextMenuProvider.hideContextMenu?() plus a _isMenuShown flag in DropdownMenu — the delegate-scoped ownership tracking is gone. If you'd rather not carry an API addition for a path with no callers, I can drop it entirely and leave this as a known limitation of popover dropdowns. Leaving the thread open for your call.
The reason will be displayed to describe this comment to others. Learn more.
🤖 Update: I went ahead and removed the hook in cba1c79 (the hideContextMenu provider/service methods, the dropdown flag and their tests). Its only path is a secondary: true quick input button, which nothing creates today, and a reviewer also found the flag could stay set if a menu never opened. So second-click-closes for a popover dropdown is a known limitation until a real producer exists; your read of the blocker for regular menus stands. Easy to restore if you want it — leaving the thread open for you.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because showing a context menu twice with the same delegate can clear the replacement’s ownership, preventing a subsequent hide from closing it.
Drop the speculative zero-size owner observer and popover cancel
semantics, and scope the dropdown hide to a shown flag with an optional
no-arg hideContextMenu instead of delegate-scoped ownership tracking.
Co-authored-by: Copilot <[email protected]>
… hide hook
contextview.css does not reach a popover attached to an owner inside a
shadow root, so add the same reset rule to that shadow root. Remove the
hideContextMenu hook again: its only path, secondary quick input buttons,
has no caller today.
Co-authored-by: Copilot <[email protected]>
SteVen Batten (@sbatten) heads-up: main CI has failed 3 times in a row on Linux X64 Unit Tests (Electron) since this PR merged (491449 at f7c0389505, which is this merge, then 491461 and 491479). The run before, 491436, was clean, and the only other commit in that range touches extensions/copilot. The test that fails is in a different area: ChatListWidget › uses the request bubble as the sticky source and content.
hoverRestoredState: {
+ sourceBackground: 'rgb(4, 5, 6)', // hover color
- sourceBackground: 'rgb(1, 2, 3)',
sourceSynchronized: false, // the .request-bubble-hovered class *was* removed
What the diff shows: the class-driven hover was cleared, but the bubble still has the hover background. The only other rule that sets it is .rendered-markdown.clickable:hover in chat.css, so the bubble is under a real pointer hover. That's only possible if the Electron test window is mapped and receiving the X11 pointer.
Likely trigger (unconfirmed, I haven't reproduced on Linux): this PR's new electron-browser tests (quickInputFocusOut.test.ts) call the new vscode:test-set-web-contents-focus handler, which runs webContents.focus() and adds and removes a focused WebContentsView on the hidden test window. In the single-page Electron run, those tests run before the chat tests. On Linux (Xvfb), focusing the hidden window seems to make it take part in pointer hover, so :hover now matches whatever sits under the Xvfb pointer, which here is the sticky source bubble. Windows and macOS CI don't hit it.
Possible fixes, your call:
In the ChatListWidget test (cheap and deterministic): set container.style.pointerEvents = 'none' for these hover assertions. The synthetic mouseenter/mouseleave it dispatches still fire, but a real pointer can no longer apply :hover.
In the focus helper: leave the window as unfocused/unmapped as it was before, so later suites don't see pointer hover.
The 05:00 UTC insider runs Linux Electron unit tests, so it will fail on this too. cc Justin Chen (@justschen), who owns the sticky-scroll test. We have no PR open. Happy to send (1) if you'd like.
…Linux Electron
Under Xvfb, the real pointer stays over the test window once a suite activates it, so :hover applies to whatever a later suite renders there. That caused the sticky request bubble (#344806) and Part Grid (#345683) main CI breaks. The hover detector now resets by sending mouseLeave to the page, and detector resets may be async.
Co-authored-by: Copilot <[email protected]>
…Linux Electron
Under Xvfb, the real pointer stays over the test window once a suite activates it, so :hover applies to whatever a later suite renders there. That caused the sticky request bubble (#344806) and Part Grid (#345683) main CI breaks. The hover detector now resets by sending mouseLeave to the page, and detector resets may be async.
Co-authored-by: Copilot <[email protected]>
…Linux Electron (#346645)
* test: move the pointer off the window after every top-level suite on Linux Electron
Under Xvfb, the real pointer stays over the test window once a suite activates it, so :hover applies to whatever a later suite renders there. That caused the sticky request bubble (#344806) and Part Grid (#345683) main CI breaks. The hover detector now resets by sending mouseLeave to the page, and detector resets may be async.
Co-authored-by: Copilot <[email protected]>
* test: cover asynchronous and failing isolation detector resets
Co-authored-by: Copilot <[email protected]>
---------
Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Closes #153267
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.