diff --git a/src/vs/base/browser/ui/dialog/dialog.ts b/src/vs/base/browser/ui/dialog/dialog.ts index 2ed8d24fadf..a26806c6e43 100644 --- a/src/vs/base/browser/ui/dialog/dialog.ts +++ b/src/vs/base/browser/ui/dialog/dialog.ts @@ -37,7 +37,6 @@ export interface IDialogOptions { readonly icon?: ThemeIcon; readonly buttonDetails?: string[]; readonly disableCloseAction?: boolean; - readonly closeOnLinkClick?: boolean; readonly disableDefaultAction?: boolean; readonly buttonStyles: IButtonStyles; readonly checkboxStyles: ICheckboxStyles; @@ -212,20 +211,6 @@ export class Dialog extends Disposable { return; }; - if (this.options.closeOnLinkClick) { - for (const el of this.messageContainer.getElementsByTagName('a')) { - this._register(addDisposableListener(el, EventType.CLICK, () => { - setTimeout(close); // HACK to ensure the link action is triggered before the dialog is closed - })); - this._register(addDisposableListener(el, EventType.KEY_DOWN, (e: KeyboardEvent) => { - const evt = new StandardKeyboardEvent(e); - if (evt.equals(KeyCode.Enter)) { - setTimeout(close); // HACK to ensure the link action is triggered before the dialog is closed - } - })); - } - } - const buttonBar = this.buttonBar = this._register(new ButtonBar(this.buttonsContainer)); const buttonMap = this.rearrangeButtons(this.buttons, this.options.cancelId); diff --git a/src/vs/platform/dialogs/common/dialogs.ts b/src/vs/platform/dialogs/common/dialogs.ts index 96259d6807e..dc1c785356e 100644 --- a/src/vs/platform/dialogs/common/dialogs.ts +++ b/src/vs/platform/dialogs/common/dialogs.ts @@ -278,7 +278,6 @@ export interface ICustomDialogOptions { readonly classes?: string[]; readonly icon?: ThemeIcon; readonly disableCloseAction?: boolean; - readonly closeOnLinkClick?: boolean; } export interface ICustomDialogMarkdown { diff --git a/src/vs/platform/environment/common/environmentService.ts b/src/vs/platform/environment/common/environmentService.ts index 1984abb76c8..7004dd4252b 100644 --- a/src/vs/platform/environment/common/environmentService.ts +++ b/src/vs/platform/environment/common/environmentService.ts @@ -252,7 +252,7 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron return undefined; } - editSessionId: string | undefined = this.args['editSessionId']; + get editSessionId(): string | undefined { return this.args['editSessionId']; } get continueOn(): string | undefined { return this.args['continueOn']; diff --git a/src/vs/workbench/browser/actions/textInputActions.ts b/src/vs/workbench/browser/actions/textInputActions.ts index 20b277dee3c..0c0d7d1386f 100644 --- a/src/vs/workbench/browser/actions/textInputActions.ts +++ b/src/vs/workbench/browser/actions/textInputActions.ts @@ -16,11 +16,53 @@ import { StandardMouseEvent } from '../../../base/browser/mouseEvent.js'; import { Event as BaseEvent } from '../../../base/common/event.js'; import { Lazy } from '../../../base/common/lazy.js'; +export function createTextInputActions(clipboardService: IClipboardService): IAction[] { + return [ + + // Undo/Redo + new Action('undo', localize('undo', "Undo"), undefined, true, async () => getActiveDocument().execCommand('undo')), + new Action('redo', localize('redo', "Redo"), undefined, true, async () => getActiveDocument().execCommand('redo')), + new Separator(), + + // Cut / Copy / Paste + new Action('editor.action.clipboardCutAction', localize('cut', "Cut"), undefined, true, async () => getActiveDocument().execCommand('cut')), + new Action('editor.action.clipboardCopyAction', localize('copy', "Copy"), undefined, true, async () => getActiveDocument().execCommand('copy')), + new Action('editor.action.clipboardPasteAction', localize('paste', "Paste"), undefined, true, async element => { + + // Native: paste is supported + if (isNative) { + getActiveDocument().execCommand('paste'); + } + + // Web: paste is not supported due to security reasons + else { + const clipboardText = await clipboardService.readText(); + if ( + isHTMLTextAreaElement(element) || + isHTMLInputElement(element) + ) { + const selectionStart = element.selectionStart || 0; + const selectionEnd = element.selectionEnd || 0; + + element.value = `${element.value.substring(0, selectionStart)}${clipboardText}${element.value.substring(selectionEnd, element.value.length)}`; + element.selectionStart = selectionStart + clipboardText.length; + element.selectionEnd = element.selectionStart; + element.dispatchEvent(new Event('input', { bubbles: true, cancelable: true })); + } + } + }), + new Separator(), + + // Select All + new Action('editor.action.selectAll', localize('selectAll', "Select All"), undefined, true, async () => getActiveDocument().execCommand('selectAll')) + ]; +} + export class TextInputActionsProvider extends Disposable implements IWorkbenchContribution { static readonly ID = 'workbench.contrib.textInputActionsProvider'; - private readonly textInputActions = new Lazy(() => this.createActions()); + private readonly textInputActions = new Lazy(() => createTextInputActions(this.clipboardService)); constructor( @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, @@ -32,48 +74,6 @@ export class TextInputActionsProvider extends Disposable implements IWorkbenchCo this.registerListeners(); } - private createActions(): IAction[] { - return [ - - // Undo/Redo - new Action('undo', localize('undo', "Undo"), undefined, true, async () => getActiveDocument().execCommand('undo')), - new Action('redo', localize('redo', "Redo"), undefined, true, async () => getActiveDocument().execCommand('redo')), - new Separator(), - - // Cut / Copy / Paste - new Action('editor.action.clipboardCutAction', localize('cut', "Cut"), undefined, true, async () => getActiveDocument().execCommand('cut')), - new Action('editor.action.clipboardCopyAction', localize('copy', "Copy"), undefined, true, async () => getActiveDocument().execCommand('copy')), - new Action('editor.action.clipboardPasteAction', localize('paste', "Paste"), undefined, true, async element => { - - // Native: paste is supported - if (isNative) { - getActiveDocument().execCommand('paste'); - } - - // Web: paste is not supported due to security reasons - else { - const clipboardText = await this.clipboardService.readText(); - if ( - isHTMLTextAreaElement(element) || - isHTMLInputElement(element) - ) { - const selectionStart = element.selectionStart || 0; - const selectionEnd = element.selectionEnd || 0; - - element.value = `${element.value.substring(0, selectionStart)}${clipboardText}${element.value.substring(selectionEnd, element.value.length)}`; - element.selectionStart = selectionStart + clipboardText.length; - element.selectionEnd = element.selectionStart; - element.dispatchEvent(new Event('input', { bubbles: true, cancelable: true })); - } - } - }), - new Separator(), - - // Select All - new Action('editor.action.selectAll', localize('selectAll', "Select All"), undefined, true, async () => getActiveDocument().execCommand('selectAll')) - ]; - } - private registerListeners(): void { // Context menu support in input/textarea diff --git a/src/vs/workbench/browser/parts/dialogs/dialogHandler.ts b/src/vs/workbench/browser/parts/dialogs/dialogHandler.ts index b80950387c8..21f62b646c2 100644 --- a/src/vs/workbench/browser/parts/dialogs/dialogHandler.ts +++ b/src/vs/workbench/browser/parts/dialogs/dialogHandler.ts @@ -137,7 +137,6 @@ export class BrowserDialogHandler extends AbstractDialogHandler { renderBody, icon: customOptions?.icon, disableCloseAction: customOptions?.disableCloseAction, - closeOnLinkClick: customOptions?.closeOnLinkClick, buttonDetails: customOptions?.buttonDetails, checkboxLabel: checkbox?.label, checkboxChecked: checkbox?.checked, diff --git a/src/vs/workbench/contrib/terminalContrib/find/browser/terminalFindWidget.ts b/src/vs/workbench/contrib/terminalContrib/find/browser/terminalFindWidget.ts index ba91e210b46..9c079280d62 100644 --- a/src/vs/workbench/contrib/terminalContrib/find/browser/terminalFindWidget.ts +++ b/src/vs/workbench/contrib/terminalContrib/find/browser/terminalFindWidget.ts @@ -15,11 +15,12 @@ import { IKeybindingService } from '../../../../../platform/keybinding/common/ke import { Event } from '../../../../../base/common/event.js'; import type { ISearchOptions } from '@xterm/addon-search'; import { IClipboardService } from '../../../../../platform/clipboard/common/clipboardService.js'; -import { openContextMenu } from './textInputContextMenu.js'; import { IDisposable } from '../../../../../base/common/lifecycle.js'; import { IHoverService } from '../../../../../platform/hover/browser/hover.js'; import { TerminalFindCommandId } from '../common/terminal.find.js'; import { TerminalClipboardContribution } from '../../clipboard/browser/terminal.clipboard.contribution.js'; +import { StandardMouseEvent } from '../../../../../base/browser/mouseEvent.js'; +import { createTextInputActions } from '../../../../browser/actions/textInputActions.js'; const TERMINAL_FIND_WIDGET_INITIAL_WIDTH = 419; @@ -74,7 +75,15 @@ export class TerminalFindWidget extends SimpleFindWidget { } const findInputDomNode = this.getFindInputDomNode(); this._register(dom.addDisposableListener(findInputDomNode, 'contextmenu', (event) => { - openContextMenu(dom.getWindow(findInputDomNode), event, clipboardService, contextMenuService); + const targetWindow = dom.getWindow(findInputDomNode); + const standardEvent = new StandardMouseEvent(targetWindow, event); + const actions = createTextInputActions(clipboardService); + + contextMenuService.showContextMenu({ + getAnchor: () => standardEvent, + getActions: () => actions, + getActionsContext: () => event.target, + }); event.stopPropagation(); })); this._register(themeService.onDidColorThemeChange(() => { diff --git a/src/vs/workbench/contrib/terminalContrib/find/browser/textInputContextMenu.ts b/src/vs/workbench/contrib/terminalContrib/find/browser/textInputContextMenu.ts deleted file mode 100644 index d0ba875c3a7..00000000000 --- a/src/vs/workbench/contrib/terminalContrib/find/browser/textInputContextMenu.ts +++ /dev/null @@ -1,63 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { getActiveWindow, isHTMLInputElement, isHTMLTextAreaElement } from '../../../../../base/browser/dom.js'; -import { StandardMouseEvent } from '../../../../../base/browser/mouseEvent.js'; -import { Action, IAction, Separator } from '../../../../../base/common/actions.js'; -import { isNative } from '../../../../../base/common/platform.js'; -import { localize } from '../../../../../nls.js'; -import { IClipboardService } from '../../../../../platform/clipboard/common/clipboardService.js'; -import { IContextMenuService } from '../../../../../platform/contextview/browser/contextView.js'; - -export function openContextMenu(targetWindow: Window, event: MouseEvent, clipboardService: IClipboardService, contextMenuService: IContextMenuService): void { - const standardEvent = new StandardMouseEvent(targetWindow, event); - - // Actions from workbench/browser/actions/textInputActions - const actions: IAction[] = []; - actions.push( - - // Undo/Redo - new Action('undo', localize('undo', "Undo"), undefined, true, async () => getActiveWindow().document.execCommand('undo')), - new Action('redo', localize('redo', "Redo"), undefined, true, async () => getActiveWindow().document.execCommand('redo')), - new Separator(), - - // Cut / Copy / Paste - new Action('editor.action.clipboardCutAction', localize('cut', "Cut"), undefined, true, async () => getActiveWindow().document.execCommand('cut')), - new Action('editor.action.clipboardCopyAction', localize('copy', "Copy"), undefined, true, async () => getActiveWindow().document.execCommand('copy')), - new Action('editor.action.clipboardPasteAction', localize('paste', "Paste"), undefined, true, async element => { - - // Native: paste is supported - if (isNative) { - getActiveWindow().document.execCommand('paste'); - } - - // Web: paste is not supported due to security reasons - else { - const clipboardText = await clipboardService.readText(); - if ( - isHTMLTextAreaElement(element) || - isHTMLInputElement(element) - ) { - const selectionStart = element.selectionStart || 0; - const selectionEnd = element.selectionEnd || 0; - - element.value = `${element.value.substring(0, selectionStart)}${clipboardText}${element.value.substring(selectionEnd, element.value.length)}`; - element.selectionStart = selectionStart + clipboardText.length; - element.selectionEnd = element.selectionStart; - } - } - }), - new Separator(), - - // Select All - new Action('editor.action.selectAll', localize('selectAll', "Select All"), undefined, true, async () => getActiveWindow().document.execCommand('selectAll')) - ); - - contextMenuService.showContextMenu({ - getAnchor: () => standardEvent, - getActions: () => actions, - getActionsContext: () => event.target, - }); -} diff --git a/src/vs/workbench/services/environment/browser/environmentService.ts b/src/vs/workbench/services/environment/browser/environmentService.ts index 2ac401d7357..03cfdb54aa8 100644 --- a/src/vs/workbench/services/environment/browser/environmentService.ts +++ b/src/vs/workbench/services/environment/browser/environmentService.ts @@ -259,7 +259,8 @@ export class BrowserWorkbenchEnvironmentService implements IBrowserWorkbenchEnvi @memoize get profile(): string | undefined { return this.payload?.get('profile'); } - editSessionId: string | undefined = this.options.editSessionId; + @memoize + get editSessionId(): string | undefined { return this.options.editSessionId; } private payload: Map | undefined;