Merge from vscode 81d7885dc2e9dc617e1522697a2966bc4025a45d (#5949)

* Merge from vscode 81d7885dc2e9dc617e1522697a2966bc4025a45d

* Fix vs unit tests and hygiene issue

* Fix strict null check issue
This commit is contained in:
Chris LaFreniere
2019-06-10 18:27:09 -07:00
committed by GitHub
parent ff38bc8143
commit d15a3fcc98
926 changed files with 19529 additions and 11383 deletions

View File

@@ -6,7 +6,7 @@
import * as DOM from 'vs/base/browser/dom';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Emitter, Event } from 'vs/base/common/event';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IStorageService } from 'vs/platform/storage/common/storage';
@@ -33,7 +33,7 @@ export class WebviewEditor extends BaseEditor {
private _content?: HTMLElement;
private _webviewContent: HTMLElement | undefined;
private _webviewFocusTrackerDisposables: IDisposable[] = [];
private readonly _webviewFocusTrackerDisposables = new DisposableStore();
private _onFocusWindowHandler?: IDisposable;
private readonly _onDidFocusWebview = this._register(new Emitter<void>());
@@ -89,7 +89,7 @@ export class WebviewEditor extends BaseEditor {
this._content = undefined;
}
this._webviewFocusTrackerDisposables = dispose(this._webviewFocusTrackerDisposables);
this._webviewFocusTrackerDisposables.dispose();
if (this._onFocusWindowHandler) {
this._onFocusWindowHandler.dispose();
@@ -304,14 +304,14 @@ export class WebviewEditor extends BaseEditor {
}
private trackFocus() {
this._webviewFocusTrackerDisposables = dispose(this._webviewFocusTrackerDisposables);
this._webviewFocusTrackerDisposables.clear();
// Track focus in webview content
const webviewContentFocusTracker = DOM.trackFocus(this._webviewContent!);
this._webviewFocusTrackerDisposables.push(webviewContentFocusTracker);
this._webviewFocusTrackerDisposables.push(webviewContentFocusTracker.onDidFocus(() => this._onDidFocusWebview.fire()));
this._webviewFocusTrackerDisposables.add(webviewContentFocusTracker);
this._webviewFocusTrackerDisposables.add(webviewContentFocusTracker.onDidFocus(() => this._onDidFocusWebview.fire()));
// Track focus in webview element
this._webviewFocusTrackerDisposables.push(this._webview!.onDidFocus(() => this._onDidFocusWebview.fire()));
this._webviewFocusTrackerDisposables.add(this._webview!.onDidFocus(() => this._onDidFocusWebview.fire()));
}
}

View File

@@ -327,4 +327,4 @@ export class RevivedWebviewEditorInput extends WebviewEditorInput {
}
return super.resolve();
}
}
}

View File

@@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IWebviewService, Webview, WebviewContentOptions, WebviewOptions } from 'vs/workbench/contrib/webview/common/webview';
export class NullWebviewService implements IWebviewService {
_serviceBrand: any;
createWebview(_options: WebviewOptions, _contentOptions: WebviewContentOptions): Webview {
throw new Error('not supported');
}
}

View File

@@ -9,6 +9,7 @@ import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import * as modes from 'vs/editor/common/modes';
import { IDisposable } from 'vs/base/common/lifecycle';
/**
* Set when the find widget in a webview is visible.
@@ -45,7 +46,7 @@ export interface WebviewContentOptions {
readonly portMappings?: ReadonlyArray<modes.IWebviewPortMapping>;
}
export interface Webview {
export interface Webview extends IDisposable {
html: string;
options: WebviewContentOptions;
@@ -68,8 +69,6 @@ export interface Webview {
layout(): void;
mountTo(parent: HTMLElement): void;
focus(): void;
dispose(): void;
reload(): void;
selectAll(): void;

View File

@@ -361,10 +361,10 @@ interface WebviewContent {
}
export class WebviewElement extends Disposable implements Webview {
private _webview: Electron.WebviewTag;
private _webview: Electron.WebviewTag | undefined;
private _ready: Promise<void>;
private _webviewFindWidget: WebviewFindWidget;
private _webviewFindWidget: WebviewFindWidget | undefined;
private _findStarted: boolean = false;
private content: WebviewContent;
@@ -404,8 +404,8 @@ export class WebviewElement extends Disposable implements Webview {
this._webview.src = 'data:text/html;charset=utf-8,%3C%21DOCTYPE%20html%3E%0D%0A%3Chtml%20lang%3D%22en%22%20style%3D%22width%3A%20100%25%3B%20height%3A%20100%25%22%3E%0D%0A%3Chead%3E%0D%0A%09%3Ctitle%3EVirtual%20Document%3C%2Ftitle%3E%0D%0A%3C%2Fhead%3E%0D%0A%3Cbody%20style%3D%22margin%3A%200%3B%20overflow%3A%20hidden%3B%20width%3A%20100%25%3B%20height%3A%20100%25%22%3E%0D%0A%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E';
this._ready = new Promise(resolve => {
const subscription = this._register(addDisposableListener(this._webview, 'ipc-message', (event) => {
if (event.channel === 'webview-ready') {
const subscription = this._register(addDisposableListener(this._webview!, 'ipc-message', (event) => {
if (this._webview && event.channel === 'webview-ready') {
// console.info('[PID Webview] ' event.args[0]);
addClass(this._webview, 'ready'); // can be found by debug command
@@ -447,7 +447,7 @@ export class WebviewElement extends Disposable implements Webview {
this.layout();
// Workaround for https://github.com/electron/electron/issues/14474
if (this._focused || document.activeElement === this._webview) {
if (this._webview && (this._focused || document.activeElement === this._webview)) {
this._webview.blur();
this._webview.focus();
}
@@ -456,6 +456,10 @@ export class WebviewElement extends Disposable implements Webview {
console.error('embedded page crashed');
}));
this._register(addDisposableListener(this._webview, 'ipc-message', (event) => {
if (!this._webview) {
return;
}
switch (event.channel) {
case 'onmessage':
if (event.args && event.args.length) {
@@ -509,10 +513,14 @@ export class WebviewElement extends Disposable implements Webview {
}
this.style(themeService.getTheme());
themeService.onThemeChange(this.style, this, this._toDispose);
this._register(themeService.onThemeChange(this.style, this));
}
public mountTo(parent: HTMLElement) {
if (!this._webview) {
return;
}
if (this._webviewFindWidget) {
parent.appendChild(this._webviewFindWidget.getDomNode()!);
}
@@ -524,10 +532,13 @@ export class WebviewElement extends Disposable implements Webview {
if (this._webview.parentElement) {
this._webview.parentElement.removeChild(this._webview);
}
this._webview = undefined;
}
this._webview = undefined!;
this._webviewFindWidget = undefined!;
if (this._webviewFindWidget) {
this._webviewFindWidget.dispose();
this._webviewFindWidget = undefined;
}
super.dispose();
}
@@ -545,7 +556,11 @@ export class WebviewElement extends Disposable implements Webview {
private _send(channel: string, ...args: any[]): void {
this._ready
.then(() => this._webview.send(channel, ...args))
.then(() => {
if (this._webview) {
this._webview.send(channel, ...args);
}
})
.catch(err => console.error(err));
}
@@ -604,6 +619,9 @@ export class WebviewElement extends Disposable implements Webview {
}
public focus(): void {
if (!this._webview) {
return;
}
this._webview.focus();
this._send('focus');
@@ -661,6 +679,9 @@ export class WebviewElement extends Disposable implements Webview {
}
public layout(): void {
if (!this._webview) {
return;
}
const contents = this._webview.getWebContents();
if (!contents || contents.isDestroyed()) {
return;
@@ -679,7 +700,7 @@ export class WebviewElement extends Disposable implements Webview {
}
public startFind(value: string, options?: Electron.FindInPageOptions) {
if (!value) {
if (!value || !this._webview) {
return;
}
@@ -706,6 +727,10 @@ export class WebviewElement extends Disposable implements Webview {
* @param value The string to search for. Empty strings are ignored.
*/
public find(value: string, previous: boolean): void {
if (!this._webview) {
return;
}
// Searching with an empty value will throw an exception
if (!value) {
return;
@@ -721,6 +746,9 @@ export class WebviewElement extends Disposable implements Webview {
}
public stopFind(keepSelection?: boolean): void {
if (!this._webview) {
return;
}
this._findStarted = false;
this._webview.stopFindInPage(keepSelection ? 'keepSelection' : 'clearSelection');
}
@@ -742,27 +770,39 @@ export class WebviewElement extends Disposable implements Webview {
}
public selectAll() {
this._webview.selectAll();
if (this._webview) {
this._webview.selectAll();
}
}
public copy() {
this._webview.copy();
if (this._webview) {
this._webview.copy();
}
}
public paste() {
this._webview.paste();
if (this._webview) {
this._webview.paste();
}
}
public cut() {
this._webview.cut();
if (this._webview) {
this._webview.cut();
}
}
public undo() {
this._webview.undo();
if (this._webview) {
this._webview.undo();
}
}
public redo() {
this._webview.redo();
if (this._webview) {
this._webview.redo();
}
}
}