提交 78707964 编写于 作者: M Matt Bierner

Reduce duplicate state for active webviews

上级 7307023e
......@@ -37,7 +37,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
private readonly _webviews = new Map<WebviewHandle, WebviewEditorInput>();
private readonly _revivers = new Set<string>();
private _activeWebview: WebviewEditorInput | undefined = undefined;
private _activeWebview: WebviewHandle | undefined = undefined;
constructor(
context: IExtHostContext,
......@@ -175,7 +175,6 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
return {
onDidClickLink: uri => this.onDidClickLink(handle, uri),
onMessage: message => this._proxy.$onMessage(handle, message),
onDidChangePosition: position => this._proxy.$onDidChangePosition(handle, position),
onDispose: () => {
this._proxy.$onDidDisposeWeview(handle).then(() => {
this._webviews.delete(handle);
......@@ -205,16 +204,25 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
}
}
if (newActiveWebview) {
if (!this._activeWebview || newActiveWebview.input !== this._activeWebview) {
this._proxy.$onDidChangeActiveWeview(newActiveWebview.handle);
this._activeWebview = newActiveWebview.input;
if (newActiveWebview && newActiveWebview.handle === this._activeWebview) {
// No change
return;
}
// Broadcast view state update for currently active
if (typeof this._activeWebview !== 'undefined') {
const oldActiveWebview = this._webviews.get(this._activeWebview);
if (oldActiveWebview) {
this._proxy.$onDidChangeWeviewViewState(this._activeWebview, false, oldActiveWebview.position);
}
}
// Then for newly active
if (newActiveWebview) {
this._proxy.$onDidChangeWeviewViewState(newActiveWebview.handle, true, activeEditor.position);
this._activeWebview = newActiveWebview.handle;
} else {
if (this._activeWebview) {
this._proxy.$onDidChangeActiveWeview(undefined);
this._activeWebview = undefined;
}
this._activeWebview = undefined;
}
}
......
......@@ -363,9 +363,8 @@ export interface MainThreadWebviewsShape extends IDisposable {
export interface ExtHostWebviewsShape {
$onMessage(handle: WebviewHandle, message: any): void;
$onDidChangeActiveWeview(handle: WebviewHandle | undefined): void;
$onDidChangeWeviewViewState(handle: WebviewHandle, active: boolean, position: EditorPosition): void;
$onDidDisposeWeview(handle: WebviewHandle): Thenable<void>;
$onDidChangePosition(handle: WebviewHandle, newPosition: EditorPosition): void;
$deserializeWebview(newWebviewHandle: WebviewHandle, viewType: string, state: any, position: EditorPosition, options: vscode.WebviewOptions): Thenable<void>;
$serializeWebview(webviewHandle: WebviewHandle): Thenable<any>;
}
......
......@@ -140,8 +140,6 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
private readonly _webviews = new Map<WebviewHandle, ExtHostWebview>();
private readonly _serializers = new Map<string, vscode.WebviewSerializer>();
private _activeWebview: ExtHostWebview | undefined;
constructor(
mainContext: IMainContext
) {
......@@ -187,21 +185,14 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
}
}
$onDidChangeActiveWeview(handle: WebviewHandle | undefined): void {
if (handle) {
const webview = this.getWebview(handle);
if (webview) {
if (webview !== this._activeWebview) {
this._activeWebview = webview;
webview.active = true;
webview.onDidChangeViewStateEmitter.fire({ viewColumn: webview.viewColumn, active: true });
}
}
} else {
if (this._activeWebview) {
this._activeWebview.active = false;
this._activeWebview.onDidChangeViewStateEmitter.fire({ viewColumn: this._activeWebview.viewColumn, active: false });
this._activeWebview = undefined;
$onDidChangeWeviewViewState(handle: WebviewHandle, active: boolean, position: Position): void {
const webview = this.getWebview(handle);
if (webview) {
const viewColumn = typeConverters.toViewColumn(position);
if (webview.active !== active || webview.viewColumn !== viewColumn) {
webview.active = active;
webview.viewColumn = viewColumn;
webview.onDidChangeViewStateEmitter.fire({ active, viewColumn });
}
}
}
......@@ -211,24 +202,10 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
if (webview) {
webview.onDisposeEmitter.fire();
this._webviews.delete(handle);
if (this._activeWebview === webview) {
this._activeWebview = undefined;
}
}
return TPromise.as(void 0);
}
$onDidChangePosition(handle: WebviewHandle, newPosition: Position): void {
const webview = this.getWebview(handle);
if (webview) {
const newViewColumn = typeConverters.toViewColumn(newPosition);
if (webview.viewColumn !== newViewColumn) {
webview.viewColumn = newViewColumn;
webview.onDidChangeViewStateEmitter.fire({ viewColumn: newViewColumn, active: webview.active });
}
}
}
$deserializeWebview(
webviewHandle: WebviewHandle,
viewType: string,
......
......@@ -228,9 +228,5 @@ export class WebviewEditorInput extends EditorInput {
public onBecameActive(position: Position): void {
this._position = position;
if (this._events && this._events.onDidChangePosition) {
this._events.onDidChangePosition(position);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册