mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
parent
6e935e3f36
commit
fded572606
|
@ -178,25 +178,6 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
|
|||
await saveAllFilesAndCloseAll();
|
||||
});
|
||||
|
||||
test.skip('correct cell selection on undo/redo of cell creation', async function () {
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
await vscode.window.showNotebookDocument(notebook);
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
await vscode.commands.executeCommand('undo');
|
||||
const selectionUndo = [...vscode.window.activeNotebookEditor!.selections];
|
||||
await vscode.commands.executeCommand('redo');
|
||||
const selectionRedo = vscode.window.activeNotebookEditor!.selections;
|
||||
|
||||
// On undo, the selected cell must be the upper cell, ie the first one
|
||||
assert.strictEqual(selectionUndo.length, 1);
|
||||
assert.strictEqual(selectionUndo[0].start, 0);
|
||||
assert.strictEqual(selectionUndo[0].end, 1);
|
||||
// On redo, the selected cell must be the new cell, ie the second one
|
||||
assert.strictEqual(selectionRedo.length, 1);
|
||||
assert.strictEqual(selectionRedo[0].start, 1);
|
||||
assert.strictEqual(selectionRedo[0].end, 2);
|
||||
});
|
||||
|
||||
test.skip('editor editing event', async function () { // TODO@rebornix https://github.com/microsoft/vscode/issues/152145
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
const editor = await vscode.window.showNotebookDocument(notebook);
|
||||
|
@ -282,41 +263,6 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
|
|||
assert.ok(cell.metadata.extraCellMetadata, `Test cell metdata not found`);
|
||||
});
|
||||
|
||||
test('edit API batch edits undo/redo', async function () { // TODO@rebornix https://github.com/microsoft/vscode/issues/155825
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
const editor = await vscode.window.showNotebookDocument(notebook);
|
||||
|
||||
const version = editor.notebook.version;
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
const cellEdit = vscode.NotebookEdit.replaceCells(new vscode.NotebookRange(1, 1), [{ kind: vscode.NotebookCellKind.Code, languageId: 'javascript', value: 'test 2', outputs: [], metadata: undefined }]);
|
||||
const metadataEdit = vscode.NotebookEdit.updateCellMetadata(0, { inputCollapsed: false });
|
||||
edit.set(notebook.uri, [cellEdit, metadataEdit]);
|
||||
const success = await vscode.workspace.applyEdit(edit);
|
||||
assert.equal(success, true);
|
||||
|
||||
assert.strictEqual(editor.notebook.cellCount, 3);
|
||||
assert.strictEqual(editor.notebook.cellAt(0)?.metadata.inputCollapsed, false);
|
||||
assert.strictEqual(version + 1, editor.notebook.version);
|
||||
|
||||
await vscode.commands.executeCommand('undo');
|
||||
assert.strictEqual(version + 2, editor.notebook.version);
|
||||
assert.strictEqual(editor.notebook.cellAt(0)?.metadata.inputCollapsed, undefined);
|
||||
assert.strictEqual(editor.notebook.cellCount, 2);
|
||||
});
|
||||
|
||||
// #126371
|
||||
test.skip('#98841, initialzation should not emit cell change events.', async function () {
|
||||
let count = 0;
|
||||
|
||||
testDisposables.push(vscode.workspace.onDidChangeNotebookDocument(() => {
|
||||
count++;
|
||||
}));
|
||||
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
await vscode.window.showNotebookDocument(notebook);
|
||||
assert.strictEqual(count, 0);
|
||||
});
|
||||
|
||||
test('notebook open', async function () {
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
const editor = await vscode.window.showNotebookDocument(notebook);
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import { ILanguageService } from 'vs/editor/common/languages/language';
|
||||
import { CellEditType, CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { TestCell, withTestNotebook } from 'vs/workbench/contrib/notebook/test/browser/testNotebookEditor';
|
||||
import { CellEditType, CellKind, SelectionStateType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { createNotebookCellList, TestCell, withTestNotebook } from 'vs/workbench/contrib/notebook/test/browser/testNotebookEditor';
|
||||
|
||||
suite('Notebook Undo/Redo', () => {
|
||||
test('Basics', async function () {
|
||||
|
@ -125,4 +125,78 @@ suite('Notebook Undo/Redo', () => {
|
|||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('Focus/selection update', async function () {
|
||||
await withTestNotebook(
|
||||
[
|
||||
['# header 1', 'markdown', CellKind.Markup, [], {}],
|
||||
['body', 'markdown', CellKind.Markup, [], {}],
|
||||
],
|
||||
async (editor, viewModel, accessor) => {
|
||||
const languageService = accessor.get(ILanguageService);
|
||||
const cellList = createNotebookCellList(accessor);
|
||||
cellList.attachViewModel(viewModel);
|
||||
cellList.setFocus([1]);
|
||||
|
||||
editor.textModel.applyEdits([{
|
||||
editType: CellEditType.Replace, index: 2, count: 0, cells: [
|
||||
new TestCell(viewModel.viewType, 3, '# header 2', 'markdown', CellKind.Code, [], languageService)
|
||||
]
|
||||
}], true, { focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }], kind: SelectionStateType.Index }, () => {
|
||||
return {
|
||||
focus: { start: 2, end: 3 }, selections: [{ start: 2, end: 3 }], kind: SelectionStateType.Index
|
||||
};
|
||||
}, undefined, true);
|
||||
assert.strictEqual(viewModel.length, 3);
|
||||
assert.strictEqual(viewModel.getVersionId(), 1);
|
||||
assert.deepStrictEqual(cellList.getFocus(), [2]);
|
||||
assert.deepStrictEqual(cellList.getSelection(), [2]);
|
||||
|
||||
await viewModel.undo();
|
||||
assert.strictEqual(viewModel.length, 2);
|
||||
assert.strictEqual(viewModel.getVersionId(), 2);
|
||||
assert.deepStrictEqual(cellList.getFocus(), [1]);
|
||||
assert.deepStrictEqual(cellList.getSelection(), [1]);
|
||||
|
||||
await viewModel.redo();
|
||||
assert.strictEqual(viewModel.length, 3);
|
||||
assert.strictEqual(viewModel.getVersionId(), 3);
|
||||
assert.deepStrictEqual(cellList.getFocus(), [2]);
|
||||
assert.deepStrictEqual(cellList.getSelection(), [2]);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('Batch edits', async function () {
|
||||
await withTestNotebook(
|
||||
[
|
||||
['# header 1', 'markdown', CellKind.Markup, [], {}],
|
||||
['body', 'markdown', CellKind.Markup, [], {}],
|
||||
],
|
||||
async (editor, viewModel, accessor) => {
|
||||
const languageService = accessor.get(ILanguageService);
|
||||
|
||||
editor.textModel.applyEdits([{
|
||||
editType: CellEditType.Replace, index: 2, count: 0, cells: [
|
||||
new TestCell(viewModel.viewType, 3, '# header 2', 'markdown', CellKind.Code, [], languageService)
|
||||
]
|
||||
}, {
|
||||
editType: CellEditType.Metadata, index: 0, metadata: { inputCollapsed: false }
|
||||
}], true, undefined, () => undefined, undefined, true);
|
||||
assert.strictEqual(viewModel.getVersionId(), 1);
|
||||
assert.deepStrictEqual(viewModel.cellAt(0)?.metadata, { inputCollapsed: false });
|
||||
|
||||
await viewModel.undo();
|
||||
assert.strictEqual(viewModel.length, 2);
|
||||
assert.strictEqual(viewModel.getVersionId(), 2);
|
||||
assert.deepStrictEqual(viewModel.cellAt(0)?.metadata, {});
|
||||
|
||||
await viewModel.redo();
|
||||
assert.strictEqual(viewModel.length, 3);
|
||||
assert.strictEqual(viewModel.getVersionId(), 3);
|
||||
assert.deepStrictEqual(viewModel.cellAt(0)?.metadata, { inputCollapsed: false });
|
||||
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue