diff --git a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts index 8d3ed04b6db..d1717c048be 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts @@ -22,6 +22,7 @@ import { ICodeEditor } from '../../../editor/browser/editorBrowser'; import { EDITOR_CONTRIBUTION_ID, WebviewWidgetContribution } from '../../parts/webview/electron-browser/webviewWidget'; import { extHostNamedCustomer } from './extHostCustomers'; import { WebviewElement } from 'vs/workbench/parts/webview/electron-browser/webviewElement'; +import { IPosition } from 'vs/editor/common/core/position'; @extHostNamedCustomer(MainContext.MainThreadWebviews) export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviver { @@ -133,10 +134,10 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv this._revivers.delete(viewType); } - $showWebviewWidget(handle: WebviewHandle, editorId: string, lineNumber: number, viewType: string, options: WebviewInputOptions): void { + $showWebviewWidget(handle: WebviewHandle, editorId: string, position: IPosition, viewType: string, options: WebviewInputOptions): void { const editor = this._editorService.getActiveEditor(); if (editor && editor.getControl()) { - (editor.getControl() as ICodeEditor).getContribution(EDITOR_CONTRIBUTION_ID).showWebviewWidget(lineNumber, 0, webview => { + (editor.getControl() as ICodeEditor).getContribution(EDITOR_CONTRIBUTION_ID).showWebviewWidget(position, webview => { this._webviews.set(handle, webview); webview.onDidClickLink(uri => this.onDidClickLink(handle, uri)); webview.onMessage(message => this._proxy.$onMessage(handle, message)); diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 80e479583b5..b7a60c3ddac 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -423,7 +423,7 @@ export function createApiFactory( return extHostWebviews.registerWebviewSerializer(viewType, serializer); }), showWebviewWidget: proposedApiFunction(extension, (editor: vscode.TextEditor, position: vscode.Position, viewType: string, title: string, options: vscode.WebviewOptions) => { - return extHostWebviews.showWebviewWidget(editor, position.line, viewType, title, options); + return extHostWebviews.showWebviewWidget(editor, position, viewType, title, options); }) }; diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 8529238873c..06940f57053 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -360,7 +360,7 @@ export interface MainThreadWebviewsShape extends IDisposable { $registerSerializer(viewType: string): void; $unregisterSerializer(viewType: string): void; - $showWebviewWidget(handle: WebviewHandle, editorId: string, lineNumber: number, viewType: string, options: vscode.WebviewOptions): void; + $showWebviewWidget(handle: WebviewHandle, editorId: string, position: IPosition, viewType: string, options: vscode.WebviewOptions): void; } export interface ExtHostWebviewsShape { diff --git a/src/vs/workbench/api/node/extHostWebview.ts b/src/vs/workbench/api/node/extHostWebview.ts index 5746e13bb29..6ddf8382e36 100644 --- a/src/vs/workbench/api/node/extHostWebview.ts +++ b/src/vs/workbench/api/node/extHostWebview.ts @@ -9,7 +9,7 @@ import { Event, Emitter } from 'vs/base/common/event'; import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters'; import { Position } from 'vs/platform/editor/common/editor'; import { TPromise } from 'vs/base/common/winjs.base'; -import { Disposable } from './extHostTypes'; +import * as types from './extHostTypes'; import { ExtHostTextEditor } from './extHostTextEditor'; export class ExtHostWebview implements vscode.Webview { @@ -173,15 +173,15 @@ export class ExtHostWebviews implements ExtHostWebviewsShape { this._serializers.set(viewType, serializer); this._proxy.$registerSerializer(viewType); - return new Disposable(() => { + return new types.Disposable(() => { this._serializers.delete(viewType); this._proxy.$unregisterSerializer(viewType); }); } - async showWebviewWidget(editor: vscode.TextEditor, lineNumber: number, viewType: string, title: string, options: vscode.WebviewOptions) { + async showWebviewWidget(editor: vscode.TextEditor, position: vscode.Position, viewType: string, title: string, options: vscode.WebviewOptions) { const handle = ExtHostWebviews.webviewHandlePool++ + ''; - this._proxy.$showWebviewWidget(handle, (editor as ExtHostTextEditor).id, lineNumber, viewType, options); + this._proxy.$showWebviewWidget(handle, (editor as ExtHostTextEditor).id, typeConverters.fromPosition(new types.Position(position.line, position.character)), viewType, options); const webview = new ExtHostWebview(handle, this._proxy, viewType, undefined, options); this._webviews.set(handle, webview); diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewWidget.ts b/src/vs/workbench/parts/webview/electron-browser/webviewWidget.ts index 78e33ac2a0f..05e5c76f6fe 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewWidget.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewWidget.ts @@ -13,14 +13,16 @@ import { WebviewElement } from 'vs/workbench/parts/webview/electron-browser/webv import { IPartService, Parts } from 'vs/workbench/services/part/common/partService'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation'; import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IPosition } from 'vs/editor/common/core/position'; export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.webview'; export class WebviewWidget extends ZoneWidget { private _webview: WebviewElement; + private _scrollable: DomScrollableElement; constructor( editor: ICodeEditor, @@ -53,16 +55,16 @@ export class WebviewWidget extends ZoneWidget { }); this._webview.mountTo(container); - const e = new DomScrollableElement(this._webview.getDomNode(), {}); - e.getDomNode().style.width = '100%'; - e.getDomNode().style.height = '100%'; - container.appendChild(e.getDomNode()); + this._scrollable = new DomScrollableElement(this._webview.getDomNode(), {}); + this._scrollable.getDomNode().style.width = '100%'; + this._scrollable.getDomNode().style.height = '100%'; + container.appendChild(this._scrollable.getDomNode()); this._delegate(this._webview); } } export interface IWebviewWidgetContribution extends IEditorContribution { - showWebviewWidget(lineNumber: number, column: number, delegate: (view: WebviewElement) => void): void; + showWebviewWidget(position: IPosition, delegate: (view: WebviewElement) => void): void; closeWebviewWidget(): void; } @@ -75,13 +77,13 @@ export class WebviewWidgetContribution implements IWebviewWidgetContribution { @IInstantiationService private readonly instantiationService: IInstantiationService ) { } - showWebviewWidget(lineNumber: number, column: number, delegate: (view: WebviewElement) => void): void { + showWebviewWidget(position: IPosition, delegate: (view: WebviewElement) => void): void { if (this._webviewWidget) { this._webviewWidget.dispose(); } this._webviewWidget = this.instantiationService.createInstance(WebviewWidget, this.editor, delegate); - this._webviewWidget.show({ lineNumber, column: 1 }, 20); + this._webviewWidget.show(position, 20); // this.webviewWidgetVisible.set(true); }