Add redo action for split cells (#17947)

* add redo action for split cells
This commit is contained in:
Barbara Valdez
2021-12-17 15:02:37 -08:00
committed by GitHub
parent 2bef6d36b0
commit 2bf3c28370
2 changed files with 20 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import { IResourceUndoRedoElement, UndoRedoElementType } from 'vs/platform/undoR
import { ICellModel, MoveDirection } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
import { NotebookModel, SplitCell } from 'sql/workbench/services/notebook/browser/models/notebookModel';
import * as TelemetryKeys from 'sql/platform/telemetry/common/telemetryKeys';
import { deepClone } from 'vs/base/common/objects';
import { localize } from 'vs/nls';
export class MoveCellEdit implements IResourceUndoRedoElement {
@@ -35,8 +36,10 @@ export class SplitCellEdit implements IResourceUndoRedoElement {
label: string = localize('splitCellEdit', "Split Cell");
resource = this.model.notebookUri;
private readonly cellOperation = { cell_operation: 'split_cell' };
private firstCellOriginalSource: string[] | string;
constructor(private model: NotebookModel, private cells: SplitCell[]) {
this.firstCellOriginalSource = deepClone(cells[0].cell.source);
}
undo(): void {
@@ -45,7 +48,8 @@ export class SplitCellEdit implements IResourceUndoRedoElement {
}
redo(): void {
// no-op currently, will add support on next release
this.model.splitCells(this.cells, this.firstCellOriginalSource);
this.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.RedoCell, this.cellOperation);
}
}

View File

@@ -706,6 +706,21 @@ export class NotebookModel extends Disposable implements INotebookModel {
}
}
public splitCells(cells: SplitCell[], firstCellOriginalSource: string | string[]): void {
cells[0].cell.source = firstCellOriginalSource;
cells[0].cell.isEditMode = true;
this.updateActiveCell(cells[0].cell);
this._contentChangedEmitter.fire({
changeType: NotebookChangeType.CellsModified,
cells: [cells[0].cell],
cellIndex: 0
});
for (let i = 1; i < cells.length; i++) {
this.insertCell(cells[i].cell, undefined, false);
}
}
public insertCell(cell: ICellModel, index?: number, addToUndoStack: boolean = true): ICellModel | undefined {
if (this.inErrorState) {
return undefined;