Fix #100329. Content providers can contribute to undo/redo stack of a notebook document.

This commit is contained in:
rebornix
2020-06-17 17:07:49 -07:00
parent ba6892d6de
commit 6c68514534
9 changed files with 300 additions and 39 deletions

View File

@@ -10,8 +10,10 @@ import { smokeTestActivate } from './notebookSmokeTestMain';
export function activate(context: vscode.ExtensionContext): any {
smokeTestActivate(context);
const _onDidChangeNotebook = new vscode.EventEmitter<vscode.NotebookDocumentEditEvent | vscode.NotebookDocumentContentChangeEvent>();
context.subscriptions.push(_onDidChangeNotebook);
context.subscriptions.push(vscode.notebook.registerNotebookContentProvider('notebookCoreTest', {
onDidChangeNotebook: new vscode.EventEmitter<vscode.NotebookDocumentEditEvent>().event,
onDidChangeNotebook: _onDidChangeNotebook.event,
openNotebook: async (_resource: vscode.Uri) => {
if (_resource.path.endsWith('empty.vsctestnb')) {
return {
@@ -71,13 +73,13 @@ export function activate(context: vscode.ExtensionContext): any {
}];
return;
},
executeCell: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell | undefined, _token: vscode.CancellationToken) => {
if (!_cell) {
_cell = _document.cells[0];
executeCell: async (document: vscode.NotebookDocument, cell: vscode.NotebookCell | undefined, _token: vscode.CancellationToken) => {
if (!cell) {
cell = document.cells[0];
}
if (_document.uri.path.endsWith('customRenderer.vsctestnb')) {
_cell.outputs = [{
if (document.uri.path.endsWith('customRenderer.vsctestnb')) {
cell.outputs = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/custom': 'test'
@@ -87,13 +89,29 @@ export function activate(context: vscode.ExtensionContext): any {
return;
}
_cell.outputs = [{
const previousOutputs = cell.outputs;
const newOutputs: vscode.CellOutput[] = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/plain': ['my output']
}
}];
cell.outputs = newOutputs;
_onDidChangeNotebook.fire({
document: document,
undo: () => {
if (cell) {
cell.outputs = previousOutputs;
}
},
redo: () => {
if (cell) {
cell.outputs = newOutputs;
}
}
});
return;
}
}));