@@ -19,7 +19,7 @@ import { ThemeIcon } from 'vs/base/common/themables';
19
19
import { TITLE_BAR_ACTIVE_BACKGROUND , TITLE_BAR_ACTIVE_FOREGROUND , TITLE_BAR_INACTIVE_FOREGROUND , TITLE_BAR_INACTIVE_BACKGROUND , TITLE_BAR_BORDER , WORKBENCH_BACKGROUND } from 'vs/workbench/common/theme' ;
20
20
import { isMacintosh , isWindows , isLinux , isWeb , isNative , platformLocale } from 'vs/base/common/platform' ;
21
21
import { Color } from 'vs/base/common/color' ;
22
- import { EventType , EventHelper , Dimension , append , $ , addDisposableListener , prepend , reset , getWindow , getActiveWindow , getWindowId } from 'vs/base/browser/dom' ;
22
+ import { EventType , EventHelper , Dimension , append , $ , addDisposableListener , prepend , reset , getWindow , getActiveWindow , getWindowId , isAncestor } from 'vs/base/browser/dom' ;
23
23
import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl' ;
24
24
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
25
25
import { Emitter , Event } from 'vs/base/common/event' ;
@@ -412,16 +412,35 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
412
412
this . primaryWindowControls = append ( primaryControlLocation === 'left' ? this . leftContent : this . rightContent , $ ( 'div.window-controls-container.primary' ) ) ;
413
413
append ( primaryControlLocation === 'left' ? this . rightContent : this . leftContent , $ ( 'div.window-controls-container.secondary' ) ) ;
414
414
415
- // Context menu on title
416
- [ EventType . CONTEXT_MENU , EventType . CLICK ] . forEach ( event => {
417
- this . _register ( addDisposableListener ( this . rootContainer , event , e => {
418
- if ( event === EventType . CONTEXT_MENU || ( isMacintosh && e . metaKey /* https://github.com/microsoft/vscode/issues/173563 */ ) ) {
419
- EventHelper . stop ( e , event === EventType . CLICK /* prevents command center from appearing */ ) ;
420
-
421
- this . onContextMenu ( e , MenuId . TitleBarContext ) ;
415
+ // Context menu over title bar: depending on the OS and the location of the click this will either be
416
+ // the overall context menu for the entire title bar or a specific title context menu.
417
+ // Windows / Linux: we only support the overall context menu on the title bar
418
+ // macOS: we support both the overall context menu and the title context menu.
419
+ // in addition, we allow Cmd+click to bring up the title context menu.
420
+ {
421
+ this . _register ( addDisposableListener ( this . rootContainer , EventType . CONTEXT_MENU , e => {
422
+ EventHelper . stop ( e ) ;
423
+
424
+ let targetMenu : MenuId ;
425
+ if ( isMacintosh && e . target instanceof HTMLElement && isAncestor ( e . target , this . title ) ) {
426
+ targetMenu = MenuId . TitleBarTitleContext ;
427
+ } else {
428
+ targetMenu = MenuId . TitleBarContext ;
422
429
}
423
- } , event === EventType . CLICK /* prevents command center from appearing */ ) ) ;
424
- } ) ;
430
+
431
+ this . onContextMenu ( e , targetMenu ) ;
432
+ } ) ) ;
433
+
434
+ if ( isMacintosh ) {
435
+ this . _register ( addDisposableListener ( this . title , EventType . CLICK , e => {
436
+ if ( e . metaKey ) {
437
+ EventHelper . stop ( e , true /* stop bubbling to prevent command center from opening */ ) ;
438
+
439
+ this . onContextMenu ( e , MenuId . TitleBarTitleContext ) ;
440
+ }
441
+ } , true /* capture phase to prevent command center from opening */ ) ) ;
442
+ }
443
+ }
425
444
426
445
// Focus action
427
446
const that = this ;
0 commit comments