Skip to content

Commit

Permalink
Fix go to action on notebook toolbar (microsoft#208061)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix authored Mar 19, 2024
1 parent 7c51753 commit 36ced2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
display: inline-flex;
}

.monaco-workbench .notebook-action-view-item-unified .monaco-dropdown {
pointer-events: none;
}

.monaco-workbench .notebookOverlay .notebook-toolbar-container .monaco-action-bar .action-item .notebook-label {
background-size: 16px;
padding: 0px 5px 0px 2px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
import * as DOM from 'vs/base/browser/dom';
import { IMenuEntryActionViewItemOptions, MenuEntryActionViewItem, SubmenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import * as types from 'vs/base/common/types';
import { EventType as TouchEventType } from 'vs/base/browser/touch';
import { IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
import { IActionProvider } from 'vs/base/browser/ui/dropdown/dropdown';
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegateFactory';
import { ICustomHover, setupCustomHover } from 'vs/base/browser/ui/hover/updatableHoverWidget';
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
import { IAction } from 'vs/base/common/actions';
import { ThemeIcon } from 'vs/base/common/themables';
import { IMenuEntryActionViewItemOptions, MenuEntryActionViewItem, SubmenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { MenuItemAction, SubmenuItemAction } from 'vs/platform/actions/common/actions';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ThemeIcon } from 'vs/base/common/themables';
import { ICustomHover, setupCustomHover } from 'vs/base/browser/ui/hover/updatableHoverWidget';
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegateFactory';

export class CodiconActionViewItem extends MenuEntryActionViewItem {

Expand Down Expand Up @@ -46,6 +49,7 @@ export class ActionViewWithLabel extends MenuEntryActionViewItem {
export class UnifiedSubmenuActionView extends SubmenuEntryActionViewItem {
private _actionLabel?: HTMLAnchorElement;
private _hover?: ICustomHover;
private _primaryAction: IAction | undefined;

constructor(
action: SubmenuItemAction,
Expand All @@ -63,18 +67,30 @@ export class UnifiedSubmenuActionView extends SubmenuEntryActionViewItem {
override render(container: HTMLElement): void {
super.render(container);
container.classList.add('notebook-action-view-item');
container.classList.add('notebook-action-view-item-unified');
this._actionLabel = document.createElement('a');
container.appendChild(this._actionLabel);

this._hover = this._register(setupCustomHover(this.options.hoverDelegate ?? getDefaultHoverDelegate('element'), this._actionLabel, ''));

this.updateLabel();

for (const event of [DOM.EventType.CLICK, DOM.EventType.MOUSE_DOWN, TouchEventType.Tap]) {
this._register(DOM.addDisposableListener(container, event, e => this.onClick(e, true)));
}
}

override onClick(event: DOM.EventLike, preserveFocus = false): void {
DOM.EventHelper.stop(event, true);
const context = types.isUndefinedOrNull(this._context) ? this.options?.useEventAsContext ? event : { preserveFocus } : this._context;
this.actionRunner.run(this._primaryAction ?? this._action, context);
}

protected override updateLabel() {
const actions = this.subActionProvider.getActions();
if (this._actionLabel) {
const primaryAction = actions[0];
this._primaryAction = primaryAction;

if (primaryAction && primaryAction instanceof MenuItemAction) {
const element = this.element;
Expand Down

0 comments on commit 36ced2d

Please sign in to comment.