From 8e02737abc8042e4c83f283ac9fd4b5f25d7af09 Mon Sep 17 00:00:00 2001 From: rebornix Date: Tue, 19 May 2020 16:55:31 -0700 Subject: [PATCH] notebookEditor.active --- .../src/notebook.test.ts | 15 ++++++++ src/vs/vscode.proposed.d.ts | 13 +++++++ .../workbench/api/common/extHostNotebook.ts | 34 +++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/extensions/vscode-notebook-tests/src/notebook.test.ts b/extensions/vscode-notebook-tests/src/notebook.test.ts index 958e642daae..55c3dd944d3 100644 --- a/extensions/vscode-notebook-tests/src/notebook.test.ts +++ b/extensions/vscode-notebook-tests/src/notebook.test.ts @@ -157,6 +157,21 @@ suite('API tests', () => { await vscode.commands.executeCommand('workbench.action.files.save'); await vscode.commands.executeCommand('workbench.action.closeAllEditors'); }); + + test('notebook editor active/visible', async function () { + const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb')); + await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); + const firstEditor = vscode.notebook.activeNotebookEditor; + assert.equal(firstEditor?.active, true); + + await vscode.commands.executeCommand('workbench.action.splitEditor'); + const secondEditor = vscode.notebook.activeNotebookEditor; + assert.equal(secondEditor?.active, true); + assert.equal(firstEditor?.active, false); + + await vscode.commands.executeCommand('workbench.action.files.save'); + await vscode.commands.executeCommand('workbench.action.closeAllEditors'); + }); }); suite('notebook workflow', () => { diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 4b89f840fec..1a8a0024670 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1773,8 +1773,21 @@ declare module 'vscode' { */ readonly selection?: NotebookCell; + /** + * The column in which this editor shows. + */ viewColumn?: ViewColumn; + /** + * Whether the panel is active (focused by the user). + */ + readonly active: boolean; + + /** + * Whether the panel is visible. + */ + readonly visible: boolean; + /** * Fired when the output hosting webview posts a message. */ diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 2147a49ad16..4c2638a294f 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -538,6 +538,33 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook private _viewColumn: vscode.ViewColumn | undefined; selection?: ExtHostCell = undefined; + + private _active: boolean = false; + get active(): boolean { + return this._active; + } + + set active(_state: boolean) { + throw readonly('active'); + } + + private _visible: boolean = false; + get visible(): boolean { + return this._visible; + } + + set visible(_state: boolean) { + throw readonly('visible'); + } + + _acceptVisibility(value: boolean) { + this._visible = value; + } + + _acceptActivity(value: boolean) { + this._active = value; + } + onDidReceiveMessage: vscode.Event = this._onDidReceiveMessage.event; constructor( @@ -1216,11 +1243,18 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN if (delta.newActiveEditor !== undefined) { if (delta.newActiveEditor) { this._activeNotebookEditor = this._editors.get(delta.newActiveEditor)?.editor; + this._activeNotebookEditor?._acceptActivity(true); this._activeNotebookDocument = this._activeNotebookEditor ? this._documents.get(this._activeNotebookEditor!.uri.toString()) : undefined; } else { this._activeNotebookEditor = undefined; this._activeNotebookDocument = undefined; } } + + this.visibleNotebookEditors.forEach((editor) => { + if (editor !== this.activeNotebookEditor) { + editor._acceptActivity(false); + } + }); } }