Implement undo/redo at cell level (#17744)

Implemented undo and redo for adding, deleting and moving cells.
This commit is contained in:
Barbara Valdez
2021-12-02 13:41:42 -08:00
committed by GitHub
parent 9b87973205
commit 8b09ba8844
9 changed files with 253 additions and 42 deletions

View File

@@ -55,6 +55,8 @@ import { NotebookViewsExtension } from 'sql/workbench/services/notebook/browser/
import { MaskedLabeledMenuItemActionItem } from 'sql/platform/actions/browser/menuEntryActionViewItem';
import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { Emitter } from 'vs/base/common/event';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyCode } from 'vs/base/common/keyCodes';
export const NOTEBOOK_SELECTOR: string = 'notebook-component';
@@ -118,6 +120,19 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
this._register(this._configurationService.onDidChangeConfiguration(e => {
this.doubleClickEditEnabled = this._configurationService.getValue('notebook.enableDoubleClickEdit');
}));
this._register(DOM.addDisposableListener(window, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
// Prevent the undo/redo from happening in other notebooks and to prevent the execution of undo/redo in the cell.
if (this.isActive() && this.activeCellId === '') {
let event = new StandardKeyboardEvent(e);
if ((event.metaKey && event.shiftKey && event.keyCode === KeyCode.KEY_Z) || event.ctrlKey && event.keyCode === KeyCode.KEY_Y) {
DOM.EventHelper.stop(event, true);
this._model.redo();
} else if ((event.ctrlKey || event.metaKey) && event.keyCode === KeyCode.KEY_Z) {
DOM.EventHelper.stop(event, true);
this._model.undo();
}
}
}));
}
ngOnInit() {