提交 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 {
this.element.style.pointerEvents = '';
}
}
public selectAll() {
if (this.element) {
this._send('execCommand', 'selectAll');
}
}
}
......@@ -187,6 +187,7 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
showFind(): void { this.withWebview(webview => webview.showFind()); }
hideFind(): void { this.withWebview(webview => webview.hideFind()); }
runFindAction(previous: boolean): void { this.withWebview(webview => webview.runFindAction(previous)); }
selectAll(): void { this.withWebview(webview => webview.selectAll()); }
public getInnerWebview() {
return this._webview.value;
......
......@@ -545,6 +545,13 @@
initData.initialScrollProgress = progress;
});
host.onMessage('execCommand', (_event, data) => {
const target = getActiveFrame();
if (!target) {
return;
}
target.contentDocument.execCommand(data);
});
trackFocus({
onFocus: () => host.postMessage('did-focus'),
......
......@@ -14,7 +14,7 @@ import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/wor
import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
import { webviewDeveloperCategory } from 'vs/workbench/contrib/webview/browser/webview';
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 { WebviewInput } from './webviewEditorInput';
import { IWebviewWorkbenchService, WebviewEditorService } from './webviewWorkbenchService';
......@@ -50,6 +50,11 @@ registerAction2(class extends WebViewEditorFindPreviousCommand {
constructor() { super(webviewActiveContextKeyExpr); }
});
registerAction2(class extends SelectAllWebviewEditorCommand {
constructor() { super(webviewActiveContextKeyExpr); }
});
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction(
SyncActionDescriptor.create(ReloadWebviewAction, ReloadWebviewAction.ID, ReloadWebviewAction.LABEL),
......
......@@ -93,6 +93,8 @@ export interface Webview extends IDisposable {
hideFind(): void;
runFindAction(previous: boolean): void;
selectAll(): void;
windowDidDragStart(): void;
windowDidDragEnd(): void;
}
......
......@@ -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 { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
export class ShowWebViewEditorFindWidgetAction extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.showFind';
......@@ -97,6 +98,29 @@ export class WebViewEditorFindPreviousCommand extends Action2 {
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 {
static readonly ID = 'workbench.action.webview.reloadWebviewAction';
static readonly LABEL = nls.localize('refreshWebviewLabel', "Reload Webviews");
......
......@@ -88,6 +88,12 @@ export class WebviewEditor extends BaseEditor {
});
}
public selectAll() {
this.withWebview(webview => {
webview.selectAll();
});
}
public reload() {
this.withWebview(webview => webview.reload());
}
......
......@@ -26,8 +26,6 @@ actionRegistry.registerWorkbenchAction(
function registerWebViewCommands(editorId: string): void {
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
if (isMacintosh) {
registerAction2(class extends webviewCommands.CopyWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
......
......@@ -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 {
public static readonly ID = 'editor.action.webvieweditor.copy';
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.
先完成此消息的编辑!
想要评论请 注册