mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 09:38:38 +01:00
Fix #100329. Content providers can contribute to undo/redo stack of a notebook document.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user