diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 4c2b1d89ee8..656d89760b1 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -5217,8 +5217,9 @@ declare module 'vscode' { * method moves it to a new column. * * @param viewColumn View column to show the panel in. Shows in the current `viewColumn` if undefined. + * @param preserveFocus When `true`, the webview will not take focus. */ - reveal(viewColumn?: ViewColumn): void; + reveal(viewColumn?: ViewColumn, preserveFocus?: boolean): void; /** * Dispose of the webview panel. @@ -5727,12 +5728,12 @@ declare module 'vscode' { * * @param viewType Identifies the type of the webview panel. * @param title Title of the panel. - * @param position Editor column to show the new panel in. + * @param showOptions Where to show the webview in the editor. If preserveFocus is set, the new webview will not take focus. * @param options Settings for the new panel. * * @return New webview panel. */ - export function createWebviewPanel(viewType: string, title: string, position: ViewColumn, options?: WebviewPanelOptions & WebviewOptions): WebviewPanel; + export function createWebviewPanel(viewType: string, title: string, showOptions: ViewColumn | { viewColumn: ViewColumn, preserveFocus?: boolean }, options?: WebviewPanelOptions & WebviewOptions): WebviewPanel; /** * Set a message to the status bar. This is a short hand for the more powerful diff --git a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts index d6255bc4454..4139bbcab43 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts @@ -69,11 +69,11 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv handle: WebviewPanelHandle, viewType: string, title: string, - column: Position, + showOptions: { viewColumn: Position, preserveFocus: boolean }, options: WebviewInputOptions, extensionFolderPath: string ): void { - const webview = this._webviewService.createWebview(MainThreadWebviews.viewType, title, column, options, extensionFolderPath, this.createWebviewEventDelegate(handle)); + const webview = this._webviewService.createWebview(MainThreadWebviews.viewType, title, showOptions, options, extensionFolderPath, this.createWebviewEventDelegate(handle)); webview.state = { viewType: viewType, state: undefined @@ -98,13 +98,13 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv webview.html = value; } - $reveal(handle: WebviewPanelHandle, column: Position | null): void { + $reveal(handle: WebviewPanelHandle, viewColumn: Position | null, preserveFocus: boolean): void { const webview = this.getWebview(handle); if (webview.isDisposed()) { return; } - this._webviewService.revealWebview(webview, column); + this._webviewService.revealWebview(webview, viewColumn, preserveFocus); } async $postMessage(handle: WebviewPanelHandle, message: any): TPromise { diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 1599bef1be7..198fc6026bb 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -409,8 +409,8 @@ export function createApiFactory( createOutputChannel(name: string): vscode.OutputChannel { return extHostOutputService.createOutputChannel(name); }, - createWebviewPanel(viewType: string, title: string, column: vscode.ViewColumn, options: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel { - return extHostWebviews.createWebview(viewType, title, column, options, extension.extensionFolderPath); + createWebviewPanel(viewType: string, title: string, showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn, preserveFocus?: boolean }, options: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel { + return extHostWebviews.createWebview(viewType, title, showOptions, options, extension.extensionFolderPath); }, createTerminal(nameOrOptions: vscode.TerminalOptions | string, shellPath?: string, shellArgs?: string[]): vscode.Terminal { if (typeof nameOrOptions === 'object') { diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 67ab3eab780..6d252aab2b4 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -354,9 +354,9 @@ export interface MainThreadTelemetryShape extends IDisposable { export type WebviewPanelHandle = string; export interface MainThreadWebviewsShape extends IDisposable { - $createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, column: EditorPosition, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionFolderPath: string): void; + $createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, viewOptions: { viewColumn: EditorPosition, preserveFocus: boolean }, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionFolderPath: string): void; $disposeWebview(handle: WebviewPanelHandle): void; - $reveal(handle: WebviewPanelHandle, column: EditorPosition | undefined): void; + $reveal(handle: WebviewPanelHandle, viewColumn: EditorPosition | null, preserveFocus: boolean): void; $setTitle(handle: WebviewPanelHandle, value: string): void; $setHtml(handle: WebviewPanelHandle, value: string): void; $postMessage(handle: WebviewPanelHandle, value: any): Thenable; diff --git a/src/vs/workbench/api/node/extHostWebview.ts b/src/vs/workbench/api/node/extHostWebview.ts index 285c1722e97..6744106acdf 100644 --- a/src/vs/workbench/api/node/extHostWebview.ts +++ b/src/vs/workbench/api/node/extHostWebview.ts @@ -171,9 +171,11 @@ export class ExtHostWebviewPanel implements vscode.WebviewPanel { return this._proxy.$postMessage(this._handle, message); } - public reveal(viewColumn?: vscode.ViewColumn): void { + public reveal(viewColumn?: vscode.ViewColumn, preserveFocus?: boolean): void { this.assertNotDisposed(); - this._proxy.$reveal(this._handle, viewColumn ? typeConverters.fromViewColumn(viewColumn) : undefined); + this._proxy.$reveal(this._handle, + viewColumn ? typeConverters.fromViewColumn(viewColumn) : undefined, + !!preserveFocus); } private assertNotDisposed() { @@ -200,13 +202,20 @@ export class ExtHostWebviews implements ExtHostWebviewsShape { createWebview( viewType: string, title: string, - viewColumn: vscode.ViewColumn, + showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn, preserveFocus?: boolean }, options: (vscode.WebviewPanelOptions & vscode.WebviewOptions) | undefined, extensionFolderPath: string ): vscode.WebviewPanel { options = options || {}; + + const viewColumn = typeof showOptions === 'object' ? showOptions.viewColumn : showOptions; + const webviewShowOptions = { + viewColumn: typeConverters.fromViewColumn(viewColumn), + preserveFocus: typeof showOptions === 'object' && !!showOptions.preserveFocus + }; + const handle = ExtHostWebviews.webviewHandlePool++ + ''; - this._proxy.$createWebviewPanel(handle, viewType, title, typeConverters.fromViewColumn(viewColumn), options, extensionFolderPath); + this._proxy.$createWebviewPanel(handle, viewType, title, webviewShowOptions, options, extensionFolderPath); const webview = new ExtHostWebview(handle, this._proxy, options); const panel = new ExtHostWebviewPanel(handle, this._proxy, viewType, title, viewColumn, options, webview); diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts index bb51f95542b..a2394bbfc06 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts @@ -21,7 +21,7 @@ export interface IWebviewEditorService { createWebview( viewType: string, title: string, - column: Position, + showOptions: { viewColumn: Position, preserveFocus: boolean }, options: WebviewInputOptions, extensionFolderPath: string, events: WebviewEvents @@ -37,7 +37,8 @@ export interface IWebviewEditorService { revealWebview( webview: WebviewEditorInput, - column: Position | null + column: Position | null, + preserveFocus: boolean ): void; registerReviver( @@ -86,24 +87,25 @@ export class WebviewEditorService implements IWebviewEditorService { createWebview( viewType: string, title: string, - column: Position, + showOptions: { viewColumn: Position, preserveFocus: boolean }, options: vscode.WebviewOptions, extensionFolderPath: string, events: WebviewEvents ): WebviewEditorInput { const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, title, options, {}, events, extensionFolderPath, undefined); - this._editorService.openEditor(webviewInput, { pinned: true }, column); + this._editorService.openEditor(webviewInput, { pinned: true, preserveFocus: showOptions.preserveFocus }, showOptions.viewColumn); return webviewInput; } revealWebview( webview: WebviewEditorInput, - column: Position | null + column: Position | null, + preserveFocus: boolean ): void { if (!column || webview.position === column) { - this._editorService.openEditor(webview, { preserveFocus: false }, column || webview.position); + this._editorService.openEditor(webview, { preserveFocus }, column || webview.position); } else { - this._editorGroupService.moveEditor(webview, webview.position, column, { preserveFocus: false }); + this._editorGroupService.moveEditor(webview, webview.position, column, { preserveFocus }); } }