Don't return symbolic columns for webview panels

Fixes #56097

When a symbolic column is used while creating a webview panel, instead set the `viewColum` as `undefined` and then resolve it once we know the real (non-symbolic) column
This commit is contained in:
Matt Bierner 2019-01-11 15:32:15 -08:00
parent adb4b04bfd
commit d3d16d2b34
2 changed files with 38 additions and 1 deletions

View file

@ -307,6 +307,38 @@ suite('Webview tests', () => {
assert.strictEqual((await response).value, false);
}
});
test('webviews should have real view column after they are created, #56097', async () => {
const webview = _register(vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.Active }, { enableScripts: true }));
// Since we used a symbolic column, we don't know what view column the webview will actually show in at first
assert.strictEqual(webview.viewColumn, undefined);
let changed = false;
const viewStateChanged = new Promise<vscode.WebviewPanelOnDidChangeViewStateEvent>((resolve) => {
webview.onDidChangeViewState(e => {
if (changed) {
throw new Error('Only expected a single view state change');
}
changed = true;
resolve(e);
}, undefined, disposables);
});
assert.strictEqual((await viewStateChanged).webviewPanel.viewColumn, vscode.ViewColumn.One);
const firstResponse = getMesssage(webview);
webview.webview.html = createHtmlDocumentWithBody(/*html*/`
<script>
const vscode = acquireVsCodeApi();
vscode.postMessage({ });
</script>`);
webview.webview.postMessage({ value: 1 });
await firstResponse;
assert.strictEqual(webview.viewColumn, vscode.ViewColumn.One);
});
});
function createHtmlDocumentWithBody(body: string): string {

View file

@ -171,8 +171,13 @@ export class ExtHostWebviewPanel implements vscode.WebviewPanel {
return this._options;
}
get viewColumn(): vscode.ViewColumn {
get viewColumn(): vscode.ViewColumn | undefined {
this.assertNotDisposed();
if (this._viewColumn < 0) {
// We are using a symbolic view column
// Return undefined instead to indicate that the real view column is currently unknown but will be resolved.
return undefined;
}
return this._viewColumn;
}