Notebooks: WYSIWYG Add Redo, Fix Shortcuts (#12752)

* Add redo and out/indent

* Check for active cell before doing shortcut

* PR feedback

* Remove unnecessary parameter
This commit is contained in:
Chris LaFreniere
2020-10-06 21:47:07 -07:00
committed by GitHub
parent 97cd9dba9f
commit 23e2a5dd12

View File

@@ -68,16 +68,20 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
}
@HostListener('document:keydown', ['$event'])
onkeydown(e) {
// use preventDefault() to avoid invoking the editor's select all
// select the active .
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
e.preventDefault();
document.execCommand('selectAll');
}
if ((e.ctrlKey || e.metaKey) && e.key === 'z') {
e.preventDefault();
document.execCommand('undo');
onkeydown(e: KeyboardEvent) {
if (this.isActive()) {
// select the active .
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
preventDefaultAndExecCommand(e, 'selectAll');
} else if ((e.metaKey && e.shiftKey && e.key === 'z') || (e.ctrlKey && e.key === 'y')) {
preventDefaultAndExecCommand(e, 'redo');
} else if ((e.ctrlKey || e.metaKey) && e.key === 'z') {
preventDefaultAndExecCommand(e, 'undo');
} else if (e.shiftKey && e.key === 'Tab') {
preventDefaultAndExecCommand(e, 'outdent');
} else if (e.key === 'Tab') {
preventDefaultAndExecCommand(e, 'indent');
}
}
}
@@ -475,3 +479,9 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
this._model.updateActiveCell(this.cellModel);
}
}
function preventDefaultAndExecCommand(e: KeyboardEvent, commandId: string) {
// use preventDefault() to avoid invoking the editor's select all
e.preventDefault();
document.execCommand(commandId);
}