💂 notebook tab switching and pick editor types.
This commit is contained in:
parent
9efb82eda9
commit
946d994d1b
|
@ -319,6 +319,70 @@ suite('notebook working copy', () => {
|
||||||
|
|
||||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('multiple tabs: dirty + clean', async function () {
|
||||||
|
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||||
|
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||||
|
|
||||||
|
await waitFor(500);
|
||||||
|
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
|
||||||
|
|
||||||
|
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
|
||||||
|
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||||
|
|
||||||
|
const secondResource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './second.vsctestnb'));
|
||||||
|
await vscode.commands.executeCommand('vscode.openWith', secondResource, 'notebookCoreTest');
|
||||||
|
await waitFor(500);
|
||||||
|
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||||
|
|
||||||
|
// make sure that the previous dirty editor is still restored in the extension host and no data loss
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true);
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true);
|
||||||
|
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection);
|
||||||
|
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 3);
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.source, 'var abc = 0;');
|
||||||
|
|
||||||
|
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||||
|
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('multiple tabs: two dirty tabs and switching', async function () {
|
||||||
|
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||||
|
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||||
|
|
||||||
|
await waitFor(500);
|
||||||
|
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
|
||||||
|
|
||||||
|
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
|
||||||
|
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||||
|
|
||||||
|
const secondResource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './second.vsctestnb'));
|
||||||
|
await vscode.commands.executeCommand('vscode.openWith', secondResource, 'notebookCoreTest');
|
||||||
|
await waitFor(500);
|
||||||
|
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
|
||||||
|
|
||||||
|
// switch to the first editor
|
||||||
|
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true);
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true);
|
||||||
|
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection);
|
||||||
|
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 3);
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.source, 'var abc = 0;');
|
||||||
|
|
||||||
|
// switch to the second editor
|
||||||
|
await vscode.commands.executeCommand('vscode.openWith', secondResource, 'notebookCoreTest');
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true);
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true);
|
||||||
|
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection);
|
||||||
|
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 2);
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.source, '');
|
||||||
|
|
||||||
|
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||||
|
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('metadata', () => {
|
suite('metadata', () => {
|
||||||
|
@ -344,6 +408,25 @@ suite('regression', () => {
|
||||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
|
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
|
||||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
|
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('#97830, #97764. Support switch to other editor types', async function () {
|
||||||
|
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
|
||||||
|
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||||
|
|
||||||
|
await waitFor(500);
|
||||||
|
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||||
|
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||||
|
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, 'var abc = 0;');
|
||||||
|
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
|
||||||
|
|
||||||
|
await vscode.commands.executeCommand('vscode.openWith', resource, 'default');
|
||||||
|
assert.equal(vscode.window.activeTextEditor?.document.uri.path, resource.path);
|
||||||
|
|
||||||
|
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||||
|
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('webview resource uri', () => {
|
suite('webview resource uri', () => {
|
||||||
|
|
4
extensions/vscode-notebook-tests/test/second.vsctestnb
Normal file
4
extensions/vscode-notebook-tests/test/second.vsctestnb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
|
@ -92,6 +92,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
|
||||||
protected readonly _contributions: { [key: string]: INotebookEditorContribution; };
|
protected readonly _contributions: { [key: string]: INotebookEditorContribution; };
|
||||||
private scrollBeyondLastLine: boolean;
|
private scrollBeyondLastLine: boolean;
|
||||||
private readonly memento: Memento;
|
private readonly memento: Memento;
|
||||||
|
private _isDisposed: boolean = false;
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -747,6 +748,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
|
||||||
|
|
||||||
let r: () => void;
|
let r: () => void;
|
||||||
DOM.scheduleAtNextAnimationFrame(() => {
|
DOM.scheduleAtNextAnimationFrame(() => {
|
||||||
|
if (this._isDisposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
relayout(cell, height);
|
relayout(cell, height);
|
||||||
r();
|
r();
|
||||||
});
|
});
|
||||||
|
@ -1226,6 +1231,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
|
this._isDisposed = true;
|
||||||
const keys = Object.keys(this._contributions);
|
const keys = Object.keys(this._contributions);
|
||||||
for (let i = 0, len = keys.length; i < len; i++) {
|
for (let i = 0, len = keys.length; i < len; i++) {
|
||||||
const contributionId = keys[i];
|
const contributionId = keys[i];
|
||||||
|
|
Loading…
Reference in a new issue