提交 8fd47cd5 编写于 作者: M Matt Bierner

Enable select all in iframe based webviews

上级 20fae66e
...@@ -286,4 +286,10 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable { ...@@ -286,4 +286,10 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
this.element.style.pointerEvents = ''; this.element.style.pointerEvents = '';
} }
} }
public selectAll() {
if (this.element) {
this._send('execCommand', 'selectAll');
}
}
} }
...@@ -187,6 +187,7 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd ...@@ -187,6 +187,7 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
showFind(): void { this.withWebview(webview => webview.showFind()); } showFind(): void { this.withWebview(webview => webview.showFind()); }
hideFind(): void { this.withWebview(webview => webview.hideFind()); } hideFind(): void { this.withWebview(webview => webview.hideFind()); }
runFindAction(previous: boolean): void { this.withWebview(webview => webview.runFindAction(previous)); } runFindAction(previous: boolean): void { this.withWebview(webview => webview.runFindAction(previous)); }
selectAll(): void { this.withWebview(webview => webview.selectAll()); }
public getInnerWebview() { public getInnerWebview() {
return this._webview.value; return this._webview.value;
......
...@@ -545,6 +545,13 @@ ...@@ -545,6 +545,13 @@
initData.initialScrollProgress = progress; initData.initialScrollProgress = progress;
}); });
host.onMessage('execCommand', (_event, data) => {
const target = getActiveFrame();
if (!target) {
return;
}
target.contentDocument.execCommand(data);
});
trackFocus({ trackFocus({
onFocus: () => host.postMessage('did-focus'), onFocus: () => host.postMessage('did-focus'),
......
...@@ -14,7 +14,7 @@ import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/wor ...@@ -14,7 +14,7 @@ import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/wor
import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor'; import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
import { webviewDeveloperCategory } from 'vs/workbench/contrib/webview/browser/webview'; import { webviewDeveloperCategory } from 'vs/workbench/contrib/webview/browser/webview';
import { WebviewEditorInputFactory } from 'vs/workbench/contrib/webview/browser/webviewEditorInputFactory'; import { WebviewEditorInputFactory } from 'vs/workbench/contrib/webview/browser/webviewEditorInputFactory';
import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetAction, WebViewEditorFindNextCommand, WebViewEditorFindPreviousCommand } from '../browser/webviewCommands'; import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetAction, WebViewEditorFindNextCommand, WebViewEditorFindPreviousCommand, SelectAllWebviewEditorCommand } from '../browser/webviewCommands';
import { WebviewEditor } from './webviewEditor'; import { WebviewEditor } from './webviewEditor';
import { WebviewInput } from './webviewEditorInput'; import { WebviewInput } from './webviewEditorInput';
import { IWebviewWorkbenchService, WebviewEditorService } from './webviewWorkbenchService'; import { IWebviewWorkbenchService, WebviewEditorService } from './webviewWorkbenchService';
...@@ -50,6 +50,11 @@ registerAction2(class extends WebViewEditorFindPreviousCommand { ...@@ -50,6 +50,11 @@ registerAction2(class extends WebViewEditorFindPreviousCommand {
constructor() { super(webviewActiveContextKeyExpr); } constructor() { super(webviewActiveContextKeyExpr); }
}); });
registerAction2(class extends SelectAllWebviewEditorCommand {
constructor() { super(webviewActiveContextKeyExpr); }
});
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions); const actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction( actionRegistry.registerWorkbenchAction(
SyncActionDescriptor.create(ReloadWebviewAction, ReloadWebviewAction.ID, ReloadWebviewAction.LABEL), SyncActionDescriptor.create(ReloadWebviewAction, ReloadWebviewAction.ID, ReloadWebviewAction.LABEL),
......
...@@ -93,6 +93,8 @@ export interface Webview extends IDisposable { ...@@ -93,6 +93,8 @@ export interface Webview extends IDisposable {
hideFind(): void; hideFind(): void;
runFindAction(previous: boolean): void; runFindAction(previous: boolean): void;
selectAll(): void;
windowDidDragStart(): void; windowDidDragStart(): void;
windowDidDragEnd(): void; windowDidDragEnd(): void;
} }
......
...@@ -13,6 +13,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis ...@@ -13,6 +13,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from 'vs/workbench/contrib/webview/browser/webview'; import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from 'vs/workbench/contrib/webview/browser/webview';
import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor'; import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
export class ShowWebViewEditorFindWidgetAction extends Action2 { export class ShowWebViewEditorFindWidgetAction extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.showFind'; public static readonly ID = 'editor.action.webvieweditor.showFind';
...@@ -97,6 +98,29 @@ export class WebViewEditorFindPreviousCommand extends Action2 { ...@@ -97,6 +98,29 @@ export class WebViewEditorFindPreviousCommand extends Action2 {
getActiveWebviewEditor(accessor)?.find(true); getActiveWebviewEditor(accessor)?.find(true);
} }
} }
export class SelectAllWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.selectAll';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.selectAll', 'Select all');
constructor(contextKeyExpr: ContextKeyExpr) {
const precondition = ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey));
super({
id: SelectAllWebviewEditorCommand.ID,
title: SelectAllWebviewEditorCommand.LABEL,
keybinding: {
when: precondition,
primary: KeyMod.CtrlCmd | KeyCode.KEY_A,
weight: KeybindingWeight.EditorContrib
}
});
}
public run(accessor: ServicesAccessor, args: any): void {
getActiveWebviewEditor(accessor)?.selectAll();
}
}
export class ReloadWebviewAction extends Action { export class ReloadWebviewAction extends Action {
static readonly ID = 'workbench.action.webview.reloadWebviewAction'; static readonly ID = 'workbench.action.webview.reloadWebviewAction';
static readonly LABEL = nls.localize('refreshWebviewLabel', "Reload Webviews"); static readonly LABEL = nls.localize('refreshWebviewLabel', "Reload Webviews");
......
...@@ -88,6 +88,12 @@ export class WebviewEditor extends BaseEditor { ...@@ -88,6 +88,12 @@ export class WebviewEditor extends BaseEditor {
}); });
} }
public selectAll() {
this.withWebview(webview => {
webview.selectAll();
});
}
public reload() { public reload() {
this.withWebview(webview => webview.reload()); this.withWebview(webview => webview.reload());
} }
......
...@@ -26,8 +26,6 @@ actionRegistry.registerWorkbenchAction( ...@@ -26,8 +26,6 @@ actionRegistry.registerWorkbenchAction(
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 contextKeyExpr = ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', editorId), ContextKeyExpr.not('editorFocus') /* https://github.com/Microsoft/vscode/issues/58668 */)!;
registerAction2(class extends webviewCommands.SelectAllWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
// These commands are only needed on MacOS where we have to disable the menu bar commands // These commands are only needed on MacOS where we have to disable the menu bar commands
if (isMacintosh) { if (isMacintosh) {
registerAction2(class extends webviewCommands.CopyWebviewEditorCommand { constructor() { super(contextKeyExpr); } }); registerAction2(class extends webviewCommands.CopyWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
......
...@@ -38,28 +38,6 @@ export class OpenWebviewDeveloperToolsAction extends Action { ...@@ -38,28 +38,6 @@ export class OpenWebviewDeveloperToolsAction extends Action {
} }
} }
export class SelectAllWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.selectAll';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.selectAll', 'Select all');
constructor(contextKeyExpr: ContextKeyExpr) {
const precondition = ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey));
super({
id: SelectAllWebviewEditorCommand.ID,
title: SelectAllWebviewEditorCommand.LABEL,
keybinding: {
when: precondition,
primary: KeyMod.CtrlCmd | KeyCode.KEY_A,
weight: KeybindingWeight.EditorContrib
}
});
}
public run(accessor: ServicesAccessor, args: any): void {
withActiveWebviewBasedWebview(accessor, webview => webview.selectAll());
}
}
export class CopyWebviewEditorCommand extends Action2 { export class CopyWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.copy'; public static readonly ID = 'editor.action.webvieweditor.copy';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.copy', "Copy2"); public static readonly LABEL = nls.localize('editor.action.webvieweditor.copy', "Copy2");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册