notebookEditor.active

This commit is contained in:
rebornix 2020-05-19 16:55:31 -07:00
parent 5d59a2e671
commit 8e02737abc
3 changed files with 62 additions and 0 deletions

View file

@ -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', () => {

View file

@ -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.
*/

View file

@ -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<any> = 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);
}
});
}
}