Merge from vscode e558dc6ea73a75bd69d7a0b485f0e7e4194c66bf (#6864)

This commit is contained in:
Anthony Dresser
2019-08-21 20:44:59 -07:00
committed by GitHub
parent d2ae0f0154
commit 985bfae8a0
107 changed files with 2260 additions and 814 deletions

View File

@@ -153,6 +153,7 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
reload(): void { this.withWebview(webview => webview.reload()); }
showFind(): void { this.withWebview(webview => webview.showFind()); }
hideFind(): void { this.withWebview(webview => webview.hideFind()); }
runFindAction(previous: boolean): void { this.withWebview(webview => webview.runFindAction(previous)); }
public getInnerWebview() {
return this._webview.value;

View File

@@ -15,8 +15,8 @@ import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } fro
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
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/browser/webview';
import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetCommand } from '../browser/webviewCommands';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, webviewDeveloperCategory, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED } from 'vs/workbench/contrib/webview/browser/webview';
import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetCommand, WebViewEditorFindNextCommand, WebViewEditorFindPreviousCommand } from '../browser/webviewCommands';
import { WebviewEditor } from '../browser/webviewEditor';
import { WebviewEditorInput } from '../browser/webviewEditorInput';
import { IWebviewEditorService, WebviewEditorService } from '../browser/webviewEditorService';
@@ -58,6 +58,28 @@ function registerWebViewCommands(editorId: string): void {
weight: KeybindingWeight.EditorContrib
}
})).register();
(new WebViewEditorFindNextCommand({
id: WebViewEditorFindNextCommand.ID,
precondition: ContextKeyExpr.and(
contextKeyExpr,
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED),
kbOpts: {
primary: KeyCode.Enter,
weight: KeybindingWeight.EditorContrib
}
})).register();
(new WebViewEditorFindPreviousCommand({
id: WebViewEditorFindPreviousCommand.ID,
precondition: ContextKeyExpr.and(
contextKeyExpr,
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED),
kbOpts: {
primary: KeyMod.Shift | KeyCode.Enter,
weight: KeybindingWeight.EditorContrib
}
})).register();
}
registerWebViewCommands(WebviewEditor.ID);

View File

@@ -16,6 +16,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
* Set when the find widget in a webview is visible.
*/
export const KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE = new RawContextKey<boolean>('webviewFindWidgetVisible', false);
export const KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED = new RawContextKey<boolean>('webviewFindWidgetFocused', false);
export const IWebviewService = createDecorator<IWebviewService>('webviewService');
@@ -83,6 +84,7 @@ export interface Webview extends IDisposable {
showFind(): void;
hideFind(): void;
runFindAction(previous: boolean): void;
}
export interface WebviewElement extends Webview {

View File

@@ -32,6 +32,27 @@ export class HideWebViewEditorFindCommand extends Command {
}
}
export class WebViewEditorFindNextCommand extends Command {
public static readonly ID = 'editor.action.webvieweditor.findNext';
public runCommand(accessor: ServicesAccessor, args: any): void {
const webViewEditor = getActiveWebviewEditor(accessor);
if (webViewEditor) {
webViewEditor.find(false);
}
}
}
export class WebViewEditorFindPreviousCommand extends Command {
public static readonly ID = 'editor.action.webvieweditor.findPrevious';
public runCommand(accessor: ServicesAccessor, args: any): void {
const webViewEditor = getActiveWebviewEditor(accessor);
if (webViewEditor) {
webViewEditor.find(true);
}
}
}
export class ReloadWebviewAction extends Action {
static readonly ID = 'workbench.action.webview.reloadWebviewAction';
static readonly LABEL = nls.localize('refreshWebviewLabel', "Reload Webviews");
@@ -62,4 +83,4 @@ function getActiveWebviewEditor(accessor: ServicesAccessor): WebviewEditor | nul
const editorService = accessor.get(IEditorService);
const activeControl = editorService.activeControl as WebviewEditor;
return activeControl.isWebviewEditor ? activeControl : null;
}
}

View File

@@ -25,7 +25,6 @@ export class WebviewEditor extends BaseEditor {
private readonly _scopedContextKeyService = this._register(new MutableDisposable<IContextKeyService>());
private _findWidgetVisible: IContextKey<boolean>;
private _editorFrame?: HTMLElement;
private _content?: HTMLElement;
@@ -79,6 +78,12 @@ export class WebviewEditor extends BaseEditor {
this.withWebview(webview => webview.hideFind());
}
public find(previous: boolean) {
this.withWebview(webview => {
webview.runFindAction(previous);
});
}
public reload() {
this.withWebview(webview => webview.reload());
}

View File

@@ -268,6 +268,10 @@ export class IFrameWebview extends Disposable implements Webview {
throw new Error('Method not implemented.');
}
runFindAction(previous: boolean): void {
throw new Error('Method not implemented.');
}
public set state(state: string | undefined) {
this.content = {
html: this.content.html,

View File

@@ -4,8 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import { SimpleFindWidget } from 'vs/workbench/contrib/codeEditor/browser/find/simpleFindWidget';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED } from 'vs/workbench/contrib/webview/browser/webview';
export interface WebviewFindDelegate {
find(value: string, previous: boolean): void;
@@ -15,6 +16,7 @@ export interface WebviewFindDelegate {
}
export class WebviewFindWidget extends SimpleFindWidget {
protected _findWidgetFocused: IContextKey<boolean>;
constructor(
private readonly _delegate: WebviewFindDelegate,
@@ -22,6 +24,7 @@ export class WebviewFindWidget extends SimpleFindWidget {
@IContextKeyService contextKeyService: IContextKeyService
) {
super(contextViewService, contextKeyService);
this._findWidgetFocused = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED.bindTo(contextKeyService);
}
public find(previous: boolean) {
@@ -47,9 +50,13 @@ export class WebviewFindWidget extends SimpleFindWidget {
return false;
}
protected onFocusTrackerFocus() { }
protected onFocusTrackerFocus() {
this._findWidgetFocused.set(true);
}
protected onFocusTrackerBlur() { }
protected onFocusTrackerBlur() {
this._findWidgetFocused.reset();
}
protected onFindInputFocusTrackerFocus() { }

View File

@@ -319,7 +319,7 @@ export class ElectronWebviewBasedWebview extends Disposable implements Webview {
return;
case 'did-click-link':
let [uri] = event.args;
const [uri] = event.args;
this._onDidClickLink.fire(URI.parse(uri));
return;
@@ -334,12 +334,10 @@ export class ElectronWebviewBasedWebview extends Disposable implements Webview {
clientY: rawEvent.clientY + bounds.top,
}));
return;
}
catch (TypeError) {
} catch {
// CustomEvent was treated as MouseEvent so don't do anything - https://github.com/microsoft/vscode/issues/78915
return;
}
}
case 'did-set-content':
@@ -640,6 +638,12 @@ export class ElectronWebviewBasedWebview extends Disposable implements Webview {
}
}
public runFindAction(previous: boolean) {
if (this._webviewFindWidget) {
this._webviewFindWidget.find(previous);
}
}
public reload() {
this.doUpdateContent();
}