mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
Move undo/redo and select all to be electron specific webview elements as well
This commit is contained in:
@@ -4,11 +4,9 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import { isMacintosh } from 'vs/base/common/platform';
|
||||
import { localize } from 'vs/nls';
|
||||
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
@@ -18,7 +16,7 @@ import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/wor
|
||||
import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
|
||||
import { WebviewEditorInputFactory } from 'vs/workbench/contrib/webview/browser/webviewEditorInputFactory';
|
||||
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, webviewDeveloperCategory } from 'vs/workbench/contrib/webview/common/webview';
|
||||
import { HideWebViewEditorFindCommand, RedoWebviewEditorCommand, ReloadWebviewAction, SelectAllWebviewEditorCommand, ShowWebViewEditorFindWidgetCommand, UndoWebviewEditorCommand } from '../browser/webviewCommands';
|
||||
import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetCommand } from '../browser/webviewCommands';
|
||||
import { WebviewEditor } from '../browser/webviewEditor';
|
||||
import { WebviewEditorInput } from '../browser/webviewEditorInput';
|
||||
import { IWebviewEditorService, WebviewEditorService } from '../browser/webviewEditorService';
|
||||
@@ -37,7 +35,7 @@ registerSingleton(IWebviewEditorService, WebviewEditorService, true);
|
||||
|
||||
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
|
||||
|
||||
export function registerWebViewCommands(editorId: string): void {
|
||||
function registerWebViewCommands(editorId: string): void {
|
||||
const contextKeyExpr = ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', editorId), ContextKeyExpr.not('editorFocus') /* https://github.com/Microsoft/vscode/issues/58668 */);
|
||||
|
||||
const showNextFindWidgetCommand = new ShowWebViewEditorFindWidgetCommand({
|
||||
@@ -60,38 +58,6 @@ export function registerWebViewCommands(editorId: string): void {
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
})).register();
|
||||
|
||||
(new SelectAllWebviewEditorCommand({
|
||||
id: SelectAllWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_A,
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
})).register();
|
||||
|
||||
// These commands are only needed on MacOS where we have to disable the menu bar commands
|
||||
if (isMacintosh) {
|
||||
(new UndoWebviewEditorCommand({
|
||||
id: UndoWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_Z,
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
})).register();
|
||||
|
||||
(new RedoWebviewEditorCommand({
|
||||
id: RedoWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_Y,
|
||||
secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z],
|
||||
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z },
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
})).register();
|
||||
}
|
||||
}
|
||||
|
||||
registerWebViewCommands(WebviewEditor.ID);
|
||||
|
||||
@@ -32,39 +32,6 @@ export class HideWebViewEditorFindCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
export class SelectAllWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.selectAll';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, args: any): void {
|
||||
const webViewEditor = getActiveWebviewEditor(accessor);
|
||||
if (webViewEditor) {
|
||||
webViewEditor.selectAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class UndoWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.undo';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, args: any): void {
|
||||
const webViewEditor = getActiveWebviewEditor(accessor);
|
||||
if (webViewEditor) {
|
||||
webViewEditor.undo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class RedoWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.redo';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, args: any): void {
|
||||
const webViewEditor = getActiveWebviewEditor(accessor);
|
||||
if (webViewEditor) {
|
||||
webViewEditor.redo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ReloadWebviewAction extends Action {
|
||||
static readonly ID = 'workbench.action.webview.reloadWebviewAction';
|
||||
static readonly LABEL = nls.localize('refreshWebviewLabel', "Reload Webviews");
|
||||
|
||||
@@ -17,7 +17,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
|
||||
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
|
||||
import { EditorOptions } from 'vs/workbench/common/editor';
|
||||
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput';
|
||||
import { IWebviewService, Webview, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from 'vs/workbench/contrib/webview/common/webview';
|
||||
import { IWebviewService, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, Webview } from 'vs/workbench/contrib/webview/common/webview';
|
||||
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
|
||||
@@ -142,18 +142,6 @@ export class WebviewEditor extends BaseEditor {
|
||||
this.withWebview(webview => webview.focus());
|
||||
}
|
||||
|
||||
public selectAll(): void {
|
||||
this.withWebview(webview => webview.selectAll());
|
||||
}
|
||||
|
||||
public undo(): void {
|
||||
this.withWebview(webview => webview.undo());
|
||||
}
|
||||
|
||||
public redo(): void {
|
||||
this.withWebview(webview => webview.redo());
|
||||
}
|
||||
|
||||
public withWebview(f: (element: Webview) => void): void {
|
||||
if (this._webview) {
|
||||
f(this._webview);
|
||||
|
||||
@@ -250,27 +250,10 @@ export class IFrameWebview extends Disposable implements Webview {
|
||||
this.doUpdateContent();
|
||||
}
|
||||
|
||||
selectAll(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
copy(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
paste(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
cut(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
undo(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
redo(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
showFind(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
hideFind(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
@@ -72,11 +72,7 @@ export interface Webview extends IDisposable {
|
||||
layout(): void;
|
||||
mountTo(parent: HTMLElement): void;
|
||||
focus(): void;
|
||||
|
||||
reload(): void;
|
||||
selectAll(): void;
|
||||
undo(): void;
|
||||
redo(): void;
|
||||
|
||||
showFind(): void;
|
||||
hideFind(): void;
|
||||
|
||||
@@ -14,7 +14,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
|
||||
import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor';
|
||||
import { IWebviewService, webviewDeveloperCategory } from 'vs/workbench/contrib/webview/common/webview';
|
||||
import { CopyWebviewEditorCommand, CutWebviewEditorCommand, OpenWebviewDeveloperToolsAction, PasteWebviewEditorCommand } from 'vs/workbench/contrib/webview/electron-browser/webviewCommands';
|
||||
import * as webviewCommands from 'vs/workbench/contrib/webview/electron-browser/webviewCommands';
|
||||
import { WebviewService } from 'vs/workbench/contrib/webview/electron-browser/webviewService';
|
||||
|
||||
registerSingleton(IWebviewService, WebviewService, true);
|
||||
@@ -22,17 +22,26 @@ registerSingleton(IWebviewService, WebviewService, true);
|
||||
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
|
||||
|
||||
actionRegistry.registerWorkbenchAction(
|
||||
new SyncActionDescriptor(OpenWebviewDeveloperToolsAction, OpenWebviewDeveloperToolsAction.ID, OpenWebviewDeveloperToolsAction.LABEL),
|
||||
OpenWebviewDeveloperToolsAction.ALIAS,
|
||||
new SyncActionDescriptor(webviewCommands.OpenWebviewDeveloperToolsAction, webviewCommands.OpenWebviewDeveloperToolsAction.ID, webviewCommands.OpenWebviewDeveloperToolsAction.LABEL),
|
||||
webviewCommands.OpenWebviewDeveloperToolsAction.ALIAS,
|
||||
webviewDeveloperCategory);
|
||||
|
||||
function registerWebViewCommands(editorId: string): void {
|
||||
const contextKeyExpr = ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', editorId), ContextKeyExpr.not('editorFocus') /* https://github.com/Microsoft/vscode/issues/58668 */);
|
||||
|
||||
(new webviewCommands.SelectAllWebviewEditorCommand({
|
||||
id: webviewCommands.SelectAllWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_A,
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
})).register();
|
||||
|
||||
// These commands are only needed on MacOS where we have to disable the menu bar commands
|
||||
if (isMacintosh) {
|
||||
(new CopyWebviewEditorCommand({
|
||||
id: CopyWebviewEditorCommand.ID,
|
||||
(new webviewCommands.CopyWebviewEditorCommand({
|
||||
id: webviewCommands.CopyWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
|
||||
@@ -40,8 +49,8 @@ function registerWebViewCommands(editorId: string): void {
|
||||
}
|
||||
})).register();
|
||||
|
||||
(new PasteWebviewEditorCommand({
|
||||
id: PasteWebviewEditorCommand.ID,
|
||||
(new webviewCommands.PasteWebviewEditorCommand({
|
||||
id: webviewCommands.PasteWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_V,
|
||||
@@ -49,14 +58,34 @@ function registerWebViewCommands(editorId: string): void {
|
||||
}
|
||||
})).register();
|
||||
|
||||
(new CutWebviewEditorCommand({
|
||||
id: CutWebviewEditorCommand.ID,
|
||||
(new webviewCommands.CutWebviewEditorCommand({
|
||||
id: webviewCommands.CutWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_X,
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
})).register();
|
||||
|
||||
(new webviewCommands.UndoWebviewEditorCommand({
|
||||
id: webviewCommands.UndoWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_Z,
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
})).register();
|
||||
|
||||
(new webviewCommands.RedoWebviewEditorCommand({
|
||||
id: webviewCommands.RedoWebviewEditorCommand.ID,
|
||||
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
|
||||
kbOpts: {
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_Y,
|
||||
secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z],
|
||||
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z },
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
})).register();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,11 +32,19 @@ export class OpenWebviewDeveloperToolsAction extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
export class SelectAllWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.selectAll';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, args: any): void {
|
||||
withActiveWebviewBasedWebview(accessor, webview => webview.selectAll());
|
||||
}
|
||||
}
|
||||
|
||||
export class CopyWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.copy';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, _args: any): void {
|
||||
return withActiveWebviewBasedWebview(accessor, webview => webview.copy());
|
||||
withActiveWebviewBasedWebview(accessor, webview => webview.copy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +52,7 @@ export class PasteWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.paste';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, _args: any): void {
|
||||
return withActiveWebviewBasedWebview(accessor, webview => webview.paste());
|
||||
withActiveWebviewBasedWebview(accessor, webview => webview.paste());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +60,23 @@ export class CutWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.cut';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, _args: any): void {
|
||||
return withActiveWebviewBasedWebview(accessor, webview => webview.cut());
|
||||
withActiveWebviewBasedWebview(accessor, webview => webview.cut());
|
||||
}
|
||||
}
|
||||
|
||||
export class UndoWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.undo';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, args: any): void {
|
||||
withActiveWebviewBasedWebview(accessor, webview => webview.undo());
|
||||
}
|
||||
}
|
||||
|
||||
export class RedoWebviewEditorCommand extends Command {
|
||||
public static readonly ID = 'editor.action.webvieweditor.redo';
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, args: any): void {
|
||||
withActiveWebviewBasedWebview(accessor, webview => webview.redo());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user