From 23e2a5dd122f877822f34ccd4c90cded6a018d95 Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Tue, 6 Oct 2020 21:47:07 -0700 Subject: [PATCH] Notebooks: WYSIWYG Add Redo, Fix Shortcuts (#12752) * Add redo and out/indent * Check for active cell before doing shortcut * PR feedback * Remove unnecessary parameter --- .../browser/cellViews/textCell.component.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts index e682319569..ee7eb9cc59 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts @@ -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); +}