Rewrite how webviews are managed internally

This change attempts to do the following:

- Encapsult most of the logic for handling the webviews used for webview editors into a new WebviewEditorOverlay class
- Greatly simplify WebviewEditorInput and make it take a webview when it is created
- Move the webview creation logic up into the webviewEditorService instead of having it be inside the webviewEditor class itself

This aim of these changes is to make it possible to re-use more of the webview logic for custom editors
This commit is contained in:
Matt Bierner
2019-07-17 18:13:31 -07:00
parent 8bdcd22b62
commit 928ae46457
13 changed files with 389 additions and 451 deletions

View File

@@ -8,7 +8,7 @@ import * as modes from 'vs/editor/common/modes';
import { MainContext, MainThreadEditorInsetsShape, IExtHostContext, ExtHostEditorInsetsShape, ExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from '../common/extHostCustomers';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IWebviewService, Webview } from 'vs/workbench/contrib/webview/common/webview';
import { IWebviewService, WebviewElement } from 'vs/workbench/contrib/webview/common/webview';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { IActiveCodeEditor, IViewZone } from 'vs/editor/browser/editorBrowser';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
@@ -33,7 +33,7 @@ class EditorWebviewZone implements IViewZone {
readonly editor: IActiveCodeEditor,
readonly line: number,
readonly height: number,
readonly webview: Webview,
readonly webview: WebviewElement,
) {
this.domNode = document.createElement('div');
this.domNode.style.zIndex = '10'; // without this, the webview is not interactive
@@ -124,12 +124,11 @@ export class MainThreadEditorInsets implements MainThreadEditorInsetsShape {
$setHtml(handle: number, value: string): void {
const inset = this.getInset(handle);
inset.webview.html = value;
}
$setOptions(handle: number, options: modes.IWebviewOptions): void {
const inset = this.getInset(handle);
inset.webview.options = options;
inset.webview.contentOptions = options;
}
async $postMessage(handle: number, value: any): Promise<boolean> {