notebookEditor.visible

This commit is contained in:
rebornix 2020-05-19 17:20:11 -07:00
parent d1a59226f2
commit 5c928428df
7 changed files with 66 additions and 12 deletions

View file

@ -163,12 +163,28 @@ suite('API tests', () => {
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
const firstEditor = vscode.notebook.activeNotebookEditor;
assert.equal(firstEditor?.active, true);
assert.equal(firstEditor?.visible, true);
await vscode.commands.executeCommand('workbench.action.splitEditor');
const secondEditor = vscode.notebook.activeNotebookEditor;
assert.equal(secondEditor?.active, true);
assert.equal(secondEditor?.visible, true);
assert.equal(firstEditor?.active, false);
assert.equal(vscode.notebook.visibleNotebookEditors.length, 2);
await vscode.commands.executeCommand('workbench.action.files.newUntitledFile');
assert.equal(firstEditor?.visible, true);
assert.equal(firstEditor?.active, false);
assert.equal(secondEditor?.visible, false);
assert.equal(secondEditor?.active, false);
assert.equal(vscode.notebook.visibleNotebookEditors.length, 1);
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
assert.equal(secondEditor?.active, true);
assert.equal(secondEditor?.visible, true);
assert.equal(vscode.notebook.visibleNotebookEditors.length, 2);
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
});

View file

@ -162,6 +162,12 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
});
}));
this._register(this._notebookService.onDidChangeVisibleEditors(e => {
this._proxy.$acceptDocumentAndEditorsDelta({
visibleEditors: e
});
}));
this._register(this._notebookService.onNotebookEditorAdd(editor => {
this._addNotebookEditor(editor);
}));

View file

@ -1566,6 +1566,7 @@ export interface INotebookDocumentsAndEditorsDelta {
removedEditors?: string[];
addedEditors?: INotebookEditorAddData[];
newActiveEditor?: string | null;
visibleEditors?: string[];
}
export interface ExtHostNotebookShape {

View file

@ -1231,15 +1231,26 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
}
if (editorChanged) {
this.visibleNotebookEditors = [...this._editors.values()].map(e => e.editor);
this._onDidChangeVisibleNotebookEditors.fire(this.visibleNotebookEditors);
removedEditors.forEach(e => {
e.editor.dispose();
e.onDidReceiveMessage.dispose();
});
}
if (delta.visibleEditors) {
this.visibleNotebookEditors = delta.visibleEditors.map(id => this._editors.get(id)?.editor).filter(editor => !!editor) as ExtHostNotebookEditor[];
const visibleEditorsSet = new Set<string>();
this.visibleNotebookEditors.forEach(editor => visibleEditorsSet.add(editor.id));
[...this._editors.values()].forEach((e) => {
const newValue = visibleEditorsSet.has(e.editor.id);
e.editor._acceptVisibility(newValue);
});
this.visibleNotebookEditors = [...this._editors.values()].map(e => e.editor).filter(e => e.visible);
this._onDidChangeVisibleNotebookEditors.fire(this.visibleNotebookEditors);
}
if (delta.newActiveEditor !== undefined) {
if (delta.newActiveEditor) {
this._activeNotebookEditor = this._editors.get(delta.newActiveEditor)?.editor;
@ -1251,9 +1262,9 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
}
}
this.visibleNotebookEditors.forEach((editor) => {
if (editor !== this.activeNotebookEditor) {
editor._acceptActivity(false);
[...this._editors.values()].forEach((e) => {
if (e.editor !== this.activeNotebookEditor) {
e.editor._acceptActivity(false);
}
});
}

View file

@ -54,6 +54,7 @@ import 'vs/workbench/contrib/notebook/browser/view/output/transforms/errorTransf
import 'vs/workbench/contrib/notebook/browser/view/output/transforms/richTransform';
import { NotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
/*--------------------------------------------------------------------------------------------- */
@ -143,11 +144,22 @@ export class NotebookContribution extends Disposable implements IWorkbenchContri
open: (editor, options, group, id) => this.onEditorOpening(editor, options, group, id)
}));
this._register(this.editorService.onDidVisibleEditorsChange(() => {
const visibleNotebookEditors = editorService.visibleEditorPanes
.filter(pane => (pane as any).isNotebookEditor)
.map(pane => pane.getControl() as INotebookEditor)
.map(editor => editor.getId());
this.notebookService.updateVisibleNotebookEditor(visibleNotebookEditors);
}));
this._register(this.editorService.onDidActiveEditorChange(() => {
const activeEditorPane = editorService.activeEditorPane as any | undefined;
const notebookEditor = activeEditorPane?.isNotebookEditor ? activeEditorPane.getControl() : undefined;
if (notebookEditor) {
this.notebookService.updateActiveNotebookEditor(notebookEditor);
} else {
this.notebookService.updateActiveNotebookEditor(null);
}
}));

View file

@ -102,8 +102,10 @@ export class NotebookService extends Disposable implements INotebookService, ICu
notebookProviderInfoStore: NotebookProviderInfoStore = new NotebookProviderInfoStore();
notebookRenderersInfoStore: NotebookOutputRendererInfoStore = new NotebookOutputRendererInfoStore();
private readonly _models: { [modelId: string]: ModelData; };
private _onDidChangeActiveEditor = new Emitter<string>();
onDidChangeActiveEditor: Event<string> = this._onDidChangeActiveEditor.event;
private _onDidChangeActiveEditor = new Emitter<string | null>();
onDidChangeActiveEditor: Event<string | null> = this._onDidChangeActiveEditor.event;
private _onDidChangeVisibleEditors = new Emitter<string[]>();
onDidChangeVisibleEditors: Event<string[]> = this._onDidChangeVisibleEditors.event;
private readonly _onNotebookEditorAdd: Emitter<INotebookEditor> = this._register(new Emitter<INotebookEditor>());
public readonly onNotebookEditorAdd: Event<INotebookEditor> = this._onNotebookEditorAdd.event;
private readonly _onNotebookEditorRemove: Emitter<INotebookEditor> = this._register(new Emitter<INotebookEditor>());
@ -386,8 +388,12 @@ export class NotebookService extends Disposable implements INotebookService, ICu
}
}
updateActiveNotebookEditor(editor: INotebookEditor) {
this._onDidChangeActiveEditor.fire(editor.getId());
updateActiveNotebookEditor(editor: INotebookEditor | null) {
this._onDidChangeActiveEditor.fire(editor ? editor.getId() : null);
}
updateVisibleNotebookEditor(editors: string[]) {
this._onDidChangeVisibleEditors.fire(editors);
}
setToCopy(items: NotebookCellTextModel[]) {

View file

@ -31,7 +31,8 @@ export interface INotebookService {
_serviceBrand: undefined;
modelManager: INotebookEditorModelManager;
canResolve(viewType: string): Promise<boolean>;
onDidChangeActiveEditor: Event<string>;
onDidChangeActiveEditor: Event<string | null>;
onDidChangeVisibleEditors: Event<string[]>;
onNotebookEditorAdd: Event<IEditor>;
onNotebookEditorRemove: Event<IEditor>;
onDidChangeKernels: Event<void>;
@ -53,7 +54,8 @@ export interface INotebookService {
getContributedNotebookProvider(viewType: string): NotebookProviderInfo | undefined;
getNotebookProviderResourceRoots(): URI[];
destoryNotebookDocument(viewType: string, notebook: INotebookTextModel): void;
updateActiveNotebookEditor(editor: IEditor): void;
updateActiveNotebookEditor(editor: IEditor | null): void;
updateVisibleNotebookEditor(editors: string[]): void;
save(viewType: string, resource: URI, token: CancellationToken): Promise<boolean>;
saveAs(viewType: string, resource: URI, target: URI, token: CancellationToken): Promise<boolean>;
onDidReceiveMessage(viewType: string, editorId: string, message: any): void;