Notebooks: Pressing Escape key in markdown cell exits edit mode (#5094)

* Pressing Escape key in markdown exits edit mode

* text + code cells inactive when pressing escape
This commit is contained in:
Chris LaFreniere
2019-04-19 16:19:16 -07:00
committed by GitHub
parent 0e168e36fc
commit 432034d2cb
2 changed files with 17 additions and 2 deletions

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { OnInit, Component, Input, Inject, forwardRef, ChangeDetectorRef, SimpleChange, OnChanges } from '@angular/core';
import { OnInit, Component, Input, Inject, forwardRef, ChangeDetectorRef, SimpleChange, OnChanges, HostListener } from '@angular/core';
import { CellView } from 'sql/workbench/parts/notebook/cellViews/interfaces';
import { ICellModel } from 'sql/workbench/parts/notebook/models/modelInterfaces';
import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel';
@@ -25,6 +25,12 @@ export class CodeCellComponent extends CellView implements OnInit, OnChanges {
this._activeCellId = value;
}
@HostListener('document:keydown.escape', ['$event'])
handleKeyboardEvent() {
this.cellModel.active = false;
this._model.activeCell = undefined;
}
private _model: NotebookModel;
private _activeCellId: string;

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./textCell';
import { OnInit, Component, Input, Inject, forwardRef, ElementRef, ChangeDetectorRef, OnDestroy, ViewChild, OnChanges, SimpleChange } from '@angular/core';
import { OnInit, Component, Input, Inject, forwardRef, ElementRef, ChangeDetectorRef, OnDestroy, ViewChild, OnChanges, SimpleChange, HostListener } from '@angular/core';
import * as path from 'path';
import { localize } from 'vs/nls';
@@ -52,6 +52,15 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
}
}
@HostListener('document:keydown.escape', ['$event'])
handleKeyboardEvent() {
if (this.isEditMode) {
this.toggleEditMode(false);
}
this.cellModel.active = false;
this._model.activeCell = undefined;
}
private _content: string;
private isEditMode: boolean;
private _sanitizer: ISanitizer;