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']) @HostListener('document:keydown', ['$event'])
onkeydown(e) { onkeydown(e: KeyboardEvent) {
// use preventDefault() to avoid invoking the editor's select all if (this.isActive()) {
// select the active . // select the active .
if ((e.ctrlKey || e.metaKey) && e.key === 'a') { if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
e.preventDefault(); preventDefaultAndExecCommand(e, 'selectAll');
document.execCommand('selectAll'); } else if ((e.metaKey && e.shiftKey && e.key === 'z') || (e.ctrlKey && e.key === 'y')) {
} preventDefaultAndExecCommand(e, 'redo');
if ((e.ctrlKey || e.metaKey) && e.key === 'z') { } else if ((e.ctrlKey || e.metaKey) && e.key === 'z') {
e.preventDefault(); preventDefaultAndExecCommand(e, 'undo');
document.execCommand('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); 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);
}