Skip to content

Commit

Permalink
Fix #98036. update editor container focus when focus goes into detach…
Browse files Browse the repository at this point in the history
…ed notebook and outputs in webview.
  • Loading branch information
rebornix committed May 29, 2020
1 parent 0780b5e commit 89b16f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
Expand Up @@ -6,7 +6,7 @@
import * as DOM from 'vs/base/browser/dom';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Emitter, Event } from 'vs/base/common/event';
import { MutableDisposable } from 'vs/base/common/lifecycle';
import { MutableDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
Expand All @@ -29,6 +29,9 @@ export class NotebookEditor extends BaseEditor {
private _widget?: NotebookEditorWidget;
private _rootElement!: HTMLElement;
private dimension: DOM.Dimension | null = null;
private _widgetDisposableStore: DisposableStore = new DisposableStore();
private readonly _onDidFocusWidget = this._register(new Emitter<void>());
public get onDidFocus(): Event<any> { return this._onDidFocusWidget.event; }

constructor(
@ITelemetryService telemetryService: ITelemetryService,
Expand Down Expand Up @@ -140,6 +143,7 @@ export class NotebookEditor extends BaseEditor {
}
});

this._widgetDisposableStore.clear();

const existingEditorWidgetForInput = NotebookRegistry.getNotebookEditorWidget(input);
if (existingEditorWidgetForInput) {
Expand All @@ -166,6 +170,7 @@ export class NotebookEditor extends BaseEditor {
const viewState = this.loadTextEditorViewState(input);

this._widget.setModel(model.notebook, viewState, options);
this._widgetDisposableStore.add(this._widget.onDidFocus(() => this._onDidFocusWidget.fire()));
}

clearInput(): void {
Expand Down
Expand Up @@ -93,6 +93,9 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
private scrollBeyondLastLine: boolean;
private readonly memento: Memento;
private _isDisposed: boolean = false;
private readonly _onDidFocusWidget = this._register(new Emitter<void>());
public get onDidFocus(): Event<any> { return this._onDidFocusWidget.event; }

constructor(
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IStorageService storageService: IStorageService,
Expand Down Expand Up @@ -341,6 +344,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
}));

this._register(this.list.onDidChangeFocus(_e => this._onDidChangeActiveEditor.fire(this)));

const widgetFocusTracker = DOM.trackFocus(this.getDomNode());
this._register(widgetFocusTracker);
this._register(widgetFocusTracker.onDidFocus(() => this._onDidFocusWidget.fire()));
}

getDomNode() {
Expand Down Expand Up @@ -462,7 +469,11 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this.webview = this.instantiationService.createInstance(BackLayerWebView, this, id, document);
await this.webview.waitForInitialization();
this.webview.webview.onDidBlur(() => this.updateEditorFocus());
this.webview.webview.onDidFocus(() => this.updateEditorFocus());
this.webview.webview.onDidFocus(() => {
this.updateEditorFocus();
this._onDidFocusWidget.fire();
});

this.localStore.add(this.webview.onMessage(message => {
if (this.viewModel) {
this.notebookService.onDidReceiveMessage(this.viewModel.viewType, this.getId(), message);
Expand Down

0 comments on commit 89b16f2

Please sign in to comment.