Add undo/redo to convert cells (#17835)

* add undo/redo to convert cells
This commit is contained in:
Barbara Valdez
2021-12-07 15:51:33 -08:00
committed by GitHub
parent 4ea6805d55
commit 1651f3f8bc
3 changed files with 45 additions and 3 deletions

View File

@@ -88,3 +88,23 @@ export class AddCellEdit implements IResourceUndoRedoElement {
this.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.RedoCell, this.cellOperation);
}
}
export class ConvertCellTypeEdit implements IResourceUndoRedoElement {
type: UndoRedoElementType.Resource = UndoRedoElementType.Resource;
label: string = localize('convertCellTypeEdit', "Convert Cell Type");
resource = this.model.notebookUri;
private readonly cellOperation = { cell_operation: 'convert_cell_type' };
constructor(private model: NotebookModel, private cell: ICellModel) {
}
undo(): void {
this.model.convertCellType(this.cell, false);
this.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.UndoCell, this.cellOperation);
}
redo(): void {
this.model.convertCellType(this.cell, false);
this.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.RedoCell, this.cellOperation);
}
}

View File

@@ -35,7 +35,7 @@ import { isUUID } from 'vs/base/common/uuid';
import { TextModel } from 'vs/editor/common/model/textModel';
import { QueryTextEditor } from 'sql/workbench/browser/modelComponents/queryTextEditor';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { AddCellEdit, DeleteCellEdit, MoveCellEdit, SplitCellEdit } from 'sql/workbench/services/notebook/browser/models/cellEdit';
import { AddCellEdit, ConvertCellTypeEdit, DeleteCellEdit, MoveCellEdit, SplitCellEdit } from 'sql/workbench/services/notebook/browser/models/cellEdit';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { deepClone } from 'vs/base/common/objects';
@@ -796,10 +796,13 @@ export class NotebookModel extends Disposable implements INotebookModel {
this._onActiveCellChanged.fire(cell);
}
public convertCellType(cell: ICellModel): void {
public convertCellType(cell: ICellModel, addToUndoStack: boolean = true): void {
if (cell) {
let index = this.findCellIndex(cell);
if (index > -1) {
if (addToUndoStack) {
this.undoService.pushElement(new ConvertCellTypeEdit(this, cell));
}
// Ensure override language is reset
cell.setOverrideLanguage('');
cell.cellType = cell.cellType === CellTypes.Markdown ? CellTypes.Code : CellTypes.Markdown;