Fix selection after reverting the document

This commit is contained in:
rebornix
2020-05-06 16:42:38 -07:00
parent 4bd68b7dfe
commit e0882b95ff
4 changed files with 71 additions and 7 deletions

View File

@@ -272,3 +272,51 @@ suite('notebook undo redo', () => {
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
});
});
suite('notebook working copy', () => {
test('notebook revert on close', 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;' });
// close active editor from command will revert the file
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await waitFor(500);
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true);
assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true);
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[0], vscode.notebook.activeNotebookEditor?.selection);
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.source, 'test');
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
});
test('notebook revert', 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;' });
await vscode.commands.executeCommand('workbench.action.files.revert');
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true);
assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true);
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[0], vscode.notebook.activeNotebookEditor?.selection);
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 1);
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.source, 'test');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
});
});