Browse Source

Merge pull request #290 from afshin/capture-escape

Notebooks and consoles should swallow all Escape keydown events.
Steven Silvester 8 years ago
parent
commit
fd4e9d6017

+ 1 - 1
examples/lab/package.json

@@ -13,7 +13,7 @@
     "font-awesome": "^4.6.3",
     "font-awesome": "^4.6.3",
     "jupyter-js-services": "^0.12.5",
     "jupyter-js-services": "^0.12.5",
     "jupyterlab": "file:../../",
     "jupyterlab": "file:../../",
-    "phosphide": "^0.9.5"
+    "phosphide": "^0.10.0"
   },
   },
   "devDependencies": {
   "devDependencies": {
     "file-loader": "^0.9.0",
     "file-loader": "^0.9.0",

+ 1 - 1
jupyterlab/package.json

@@ -10,7 +10,7 @@
     "font-awesome": "^4.6.1",
     "font-awesome": "^4.6.1",
     "jupyter-js-services": "^0.14.0",
     "jupyter-js-services": "^0.14.0",
     "jupyterlab": "file:../",
     "jupyterlab": "file:../",
-    "phosphide": "^0.9.5"
+    "phosphide": "^0.10.0"
   },
   },
   "devDependencies": {
   "devDependencies": {
     "css-loader": "^0.23.1",
     "css-loader": "^0.23.1",

+ 1 - 1
package.json

@@ -18,7 +18,7 @@
     "jupyter-js-widgets": "2.0.0-dev.0",
     "jupyter-js-widgets": "2.0.0-dev.0",
     "marked": "^0.3.5",
     "marked": "^0.3.5",
     "moment": "^2.11.2",
     "moment": "^2.11.2",
-    "phosphide": "^0.9.5",
+    "phosphide": "^0.10.0",
     "phosphor-arrays": "^1.0.6",
     "phosphor-arrays": "^1.0.6",
     "phosphor-codemirror": "^0.0.1",
     "phosphor-codemirror": "^0.0.1",
     "phosphor-di": "^0.9.0",
     "phosphor-di": "^0.9.0",

+ 11 - 3
src/console/plugin.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 // Distributed under the terms of the Modified BSD License.
 
 
 import {
 import {
-  ServiceManager
+  IKernel, ISession, ServiceManager
 } from 'jupyter-js-services';
 } from 'jupyter-js-services';
 
 
 import {
 import {
@@ -110,6 +110,14 @@ function activateConsole(app: Application, services: ServiceManager, rendermime:
       }
       }
     }
     }
   },
   },
+  {
+    id: 'console:dismiss-overlays',
+    handler: () => {
+      if (tracker.activeWidget) {
+        tracker.activeWidget.content.dismissOverlays();
+      }
+    }
+  },
   {
   {
     id: 'console:execute',
     id: 'console:execute',
     handler: () => {
     handler: () => {
@@ -139,7 +147,7 @@ function activateConsole(app: Application, services: ServiceManager, rendermime:
         if (session.kernel) {
         if (session.kernel) {
           lang = specs.kernelspecs[session.kernel.name].spec.language;
           lang = specs.kernelspecs[session.kernel.name].spec.language;
         }
         }
-        manager.listRunning().then(sessions => {
+        manager.listRunning().then((sessions: ISession.IModel[]) => {
           let options = {
           let options = {
             name: widget.parent.title.text,
             name: widget.parent.title.text,
             specs,
             specs,
@@ -149,7 +157,7 @@ function activateConsole(app: Application, services: ServiceManager, rendermime:
             host: widget.parent.node
             host: widget.parent.node
           };
           };
           return selectKernel(options);
           return selectKernel(options);
-        }).then(kernelId => {
+        }).then((kernelId: IKernel.IModel) => {
           if (kernelId) {
           if (kernelId) {
             session.changeKernel(kernelId);
             session.changeKernel(kernelId);
           } else {
           } else {

+ 12 - 16
src/console/tooltip.ts

@@ -99,25 +99,21 @@ class ConsoleTooltip extends Widget {
    * Handle `after_attach` messages for the widget.
    * Handle `after_attach` messages for the widget.
    *
    *
    * #### Notes
    * #### Notes
-   * Captures window events in capture phase to dismiss the tooltip widget.
-   *
-   * Because its parent (reference) widgets use window listeners instead of
-   * document listeners, the tooltip widget must also use window listeners
-   * in the capture phase.
+   * Captures document events to dismiss the tooltip widget.
    */
    */
   protected onAfterAttach(msg: Message): void {
   protected onAfterAttach(msg: Message): void {
-    window.addEventListener('keydown', this, USE_CAPTURE);
-    window.addEventListener('mousedown', this, USE_CAPTURE);
-    window.addEventListener('scroll', this, USE_CAPTURE);
+    document.addEventListener('keydown', this, USE_CAPTURE);
+    document.addEventListener('mousedown', this, USE_CAPTURE);
+    document.addEventListener('scroll', this);
   }
   }
 
 
   /**
   /**
    * Handle `before_detach` messages for the widget.
    * Handle `before_detach` messages for the widget.
    */
    */
   protected onBeforeDetach(msg: Message): void {
   protected onBeforeDetach(msg: Message): void {
-    window.removeEventListener('keydown', this, USE_CAPTURE);
-    window.removeEventListener('mousedown', this, USE_CAPTURE);
-    window.removeEventListener('scroll', this, USE_CAPTURE);
+    document.removeEventListener('keydown', this, USE_CAPTURE);
+    document.removeEventListener('mousedown', this, USE_CAPTURE);
+    document.removeEventListener('scroll', this);
   }
   }
 
 
   /**
   /**
@@ -135,17 +131,16 @@ class ConsoleTooltip extends Widget {
    * of either the tooltip or its parent.
    * of either the tooltip or its parent.
    */
    */
   private _evtKeydown(event: KeyboardEvent) {
   private _evtKeydown(event: KeyboardEvent) {
-    let target = event.target as HTMLElement;
-
-    if (!this._reference) {
-      this.hide();
+    if (this.isHidden) {
       return;
       return;
     }
     }
 
 
-    if (this.isHidden) {
+    if (!this._reference) {
+      this.hide();
       return;
       return;
     }
     }
 
 
+    let target = event.target as HTMLElement;
     while (target !== document.documentElement) {
     while (target !== document.documentElement) {
       if (target === this._reference.node) {
       if (target === this._reference.node) {
         if (event.keyCode === 27) { // Escape key
         if (event.keyCode === 27) { // Escape key
@@ -155,6 +150,7 @@ class ConsoleTooltip extends Widget {
       }
       }
       target = target.parentElement;
       target = target.parentElement;
     }
     }
+
     this.hide();
     this.hide();
   }
   }
 
 

+ 8 - 0
src/console/widget.ts

@@ -338,6 +338,14 @@ class ConsoleWidget extends Widget {
     this.newPrompt();
     this.newPrompt();
   }
   }
 
 
+  /**
+   * Dismiss the tooltip and completion widget for a console.
+   */
+  dismissOverlays(): void {
+    this._tooltip.hide();
+    this._completion.reset();
+  }
+
   /**
   /**
    * Serialize the output.
    * Serialize the output.
    */
    */

+ 29 - 33
src/notebook/completion/widget.ts

@@ -145,6 +145,17 @@ class CompletionWidget extends Widget {
     super.dispose();
     super.dispose();
   }
   }
 
 
+  /**
+   * Reset the widget.
+   */
+  reset(): void {
+    if (this._model) {
+      this._model.reset();
+    }
+    this._activeIndex = 0;
+    this._anchorPoint = 0;
+  }
+
   /**
   /**
    * Handle the DOM events for the widget.
    * Handle the DOM events for the widget.
    *
    *
@@ -176,23 +187,19 @@ class CompletionWidget extends Widget {
 
 
   /**
   /**
    * Handle `after_attach` messages for the widget.
    * Handle `after_attach` messages for the widget.
-   *
-   * #### Notes
-   * Captures window events in capture phase to dismiss or navigate the
-   * completion widget. Captures scroll events on the anchor element to
-   * peg the completion widget's scroll position to the anchor.
    */
    */
   protected onAfterAttach(msg: Message): void {
   protected onAfterAttach(msg: Message): void {
-    window.addEventListener('keydown', this, USE_CAPTURE);
-    window.addEventListener('mousedown', this, USE_CAPTURE);
+    document.addEventListener('keydown', this, USE_CAPTURE);
+    document.addEventListener('mousedown', this, USE_CAPTURE);
   }
   }
 
 
   /**
   /**
    * Handle `before_detach` messages for the widget.
    * Handle `before_detach` messages for the widget.
    */
    */
   protected onBeforeDetach(msg: Message): void {
   protected onBeforeDetach(msg: Message): void {
-    window.removeEventListener('keydown', this, USE_CAPTURE);
-    window.removeEventListener('mousedown', this, USE_CAPTURE);
+    document.removeEventListener('keydown', this, USE_CAPTURE);
+    document.removeEventListener('mousedown', this, USE_CAPTURE);
+
     if (this._anchor) {
     if (this._anchor) {
       this._anchor.removeEventListener('scroll', this, USE_CAPTURE);
       this._anchor.removeEventListener('scroll', this, USE_CAPTURE);
     }
     }
@@ -227,7 +234,7 @@ class CompletionWidget extends Widget {
     // If there is only one item, signal and bail.
     // If there is only one item, signal and bail.
     if (items.length === 1) {
     if (items.length === 1) {
       this.selected.emit(items[0].raw);
       this.selected.emit(items[0].raw);
-      this._reset();
+      this.reset();
       return;
       return;
     }
     }
 
 
@@ -273,6 +280,9 @@ class CompletionWidget extends Widget {
    * Handle keydown events for the widget.
    * Handle keydown events for the widget.
    */
    */
   private _evtKeydown(event: KeyboardEvent) {
   private _evtKeydown(event: KeyboardEvent) {
+    if (this.isHidden || !this._anchor) {
+      return;
+    }
     let target = event.target as HTMLElement;
     let target = event.target as HTMLElement;
     while (target !== document.documentElement) {
     while (target !== document.documentElement) {
       if (target === this._anchor) {
       if (target === this._anchor) {
@@ -292,12 +302,6 @@ class CompletionWidget extends Widget {
             event.stopImmediatePropagation();
             event.stopImmediatePropagation();
             this._selectActive();
             this._selectActive();
             return;
             return;
-          case 27: // Escape key
-            event.preventDefault();
-            event.stopPropagation();
-            event.stopImmediatePropagation();
-            this._reset();
-            return;
           case 38: // Up arrow key
           case 38: // Up arrow key
           case 40: // Down arrow key
           case 40: // Down arrow key
             event.preventDefault();
             event.preventDefault();
@@ -311,15 +315,18 @@ class CompletionWidget extends Widget {
       }
       }
       target = target.parentElement;
       target = target.parentElement;
     }
     }
-    this._reset();
+    this.reset();
   }
   }
 
 
   /**
   /**
    * Handle mousedown events for the widget.
    * Handle mousedown events for the widget.
    */
    */
   private _evtMousedown(event: MouseEvent) {
   private _evtMousedown(event: MouseEvent) {
+    if (this.isHidden || !this._anchor) {
+      return;
+    }
     if (Private.nonstandardClick(event)) {
     if (Private.nonstandardClick(event)) {
-      this._reset();
+      this.reset();
       return;
       return;
     }
     }
 
 
@@ -331,7 +338,7 @@ class CompletionWidget extends Widget {
         event.stopPropagation();
         event.stopPropagation();
         event.stopImmediatePropagation();
         event.stopImmediatePropagation();
         this.selected.emit(target.dataset['value']);
         this.selected.emit(target.dataset['value']);
-        this._reset();
+        this.reset();
         return;
         return;
       }
       }
       // If the mouse event happened anywhere else in the widget, bail.
       // If the mouse event happened anywhere else in the widget, bail.
@@ -343,14 +350,14 @@ class CompletionWidget extends Widget {
       }
       }
       target = target.parentElement;
       target = target.parentElement;
     }
     }
-    this._reset();
+    this.reset();
   }
   }
 
 
   /**
   /**
    * Handle scroll events for the widget
    * Handle scroll events for the widget
    */
    */
   private _evtScroll(event: MouseEvent) {
   private _evtScroll(event: MouseEvent) {
-    if (this.isHidden) {
+    if (this.isHidden || !this._anchor) {
       return;
       return;
     }
     }
     this._setGeometry();
     this._setGeometry();
@@ -374,17 +381,6 @@ class CompletionWidget extends Widget {
     return false;
     return false;
   }
   }
 
 
-  /**
-   * Reset the widget.
-   */
-  private _reset(): void {
-    if (this._model) {
-      this._model.reset();
-    }
-    this._activeIndex = 0;
-    this._anchorPoint = 0;
-  }
-
   /**
   /**
    * Set the visible dimensions of the widget.
    * Set the visible dimensions of the widget.
    */
    */
@@ -432,7 +428,7 @@ class CompletionWidget extends Widget {
       return;
       return;
     }
     }
     this.selected.emit(active.dataset['value']);
     this.selected.emit(active.dataset['value']);
-    this._reset();
+    this.reset();
   }
   }
 
 
   private _anchor: HTMLElement = null;
   private _anchor: HTMLElement = null;

+ 4 - 0
src/notebook/notebook/panel.ts

@@ -21,6 +21,10 @@ import {
   ISignal, Signal
   ISignal, Signal
 } from 'phosphor-signaling';
 } from 'phosphor-signaling';
 
 
+import {
+  Message
+} from 'phosphor-messaging';
+
 import {
 import {
   Widget
   Widget
 } from 'phosphor-widget';
 } from 'phosphor-widget';

+ 82 - 82
src/notebook/plugin.ts

@@ -56,8 +56,8 @@ const cmdIds = {
   switchKernel: 'notebook:switch-kernel',
   switchKernel: 'notebook:switch-kernel',
   clearAllOutputs: 'notebook:clear-outputs',
   clearAllOutputs: 'notebook:clear-outputs',
   run: 'notebook-cells:run',
   run: 'notebook-cells:run',
-  runAndAdvance: 'notebook-cells:runAndAdvance',
-  runAndInsert: 'notebook-cells:runAndInsert',
+  runAndAdvance: 'notebook-cells:run-and-advance',
+  runAndInsert: 'notebook-cells:run-and-insert',
   runAll: 'notebook:run-all',
   runAll: 'notebook:run-all',
   toCode: 'notebook-cells:to-code',
   toCode: 'notebook-cells:to-code',
   toMarkdown: 'notebook-cells:to-markdown',
   toMarkdown: 'notebook-cells:to-markdown',
@@ -73,12 +73,12 @@ const cmdIds = {
   selectBelow: 'notebook-cells:select-below',
   selectBelow: 'notebook-cells:select-below',
   extendAbove: 'notebook-cells:extend-above',
   extendAbove: 'notebook-cells:extend-above',
   extendBelow: 'notebook-cells:extend-below',
   extendBelow: 'notebook-cells:extend-below',
-  editMode: 'notebook:editMode',
+  editMode: 'notebook:edit-mode',
   merge: 'notebook-cells:merge',
   merge: 'notebook-cells:merge',
   split: 'notebook-cells:split',
   split: 'notebook-cells:split',
-  commandMode: 'notebook:commandMode',
-  toggleLines: 'notebook-cells:toggle-lineNumbers',
-  toggleAllLines: 'notebook-cells:toggle-allLineNumbers',
+  commandMode: 'notebook:command-mode',
+  toggleLines: 'notebook-cells:toggle-line-numbers',
+  toggleAllLines: 'notebook-cells:toggle-all-line-numbers',
   undo: 'notebook-cells:undo',
   undo: 'notebook-cells:undo',
   redo: 'notebook-cells:redo',
   redo: 'notebook-cells:redo',
   markdown1: 'notebook-cells:markdown-header1',
   markdown1: 'notebook-cells:markdown-header1',
@@ -173,7 +173,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
 
 
   app.commands.add([
   app.commands.add([
   {
   {
-    id: cmdIds['runAndAdvance'],
+    id: cmdIds.runAndAdvance,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -182,7 +182,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['run'],
+    id: cmdIds.run,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -191,7 +191,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['runAndInsert'],
+    id: cmdIds.runAndInsert,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -200,7 +200,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['runAll'],
+    id: cmdIds.runAll,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -209,7 +209,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['restart'],
+    id: cmdIds.restart,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -218,7 +218,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['restartClear'],
+    id: cmdIds.restartClear,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -232,7 +232,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['restartRunAll'],
+    id: cmdIds.restartRunAll,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -244,7 +244,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['clearAllOutputs'],
+    id: cmdIds.clearAllOutputs,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -253,7 +253,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['clearOutputs'],
+    id: cmdIds.clearOutputs,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -262,7 +262,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['interrupt'],
+    id: cmdIds.interrupt,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let kernel = tracker.activeWidget.context.kernel;
         let kernel = tracker.activeWidget.context.kernel;
@@ -273,7 +273,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['toCode'],
+    id: cmdIds.toCode,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -282,7 +282,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['toMarkdown'],
+    id: cmdIds.toMarkdown,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -291,7 +291,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['toRaw'],
+    id: cmdIds.toRaw,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -300,7 +300,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['cut'],
+    id: cmdIds.cut,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -309,7 +309,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['copy'],
+    id: cmdIds.copy,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -318,7 +318,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['paste'],
+    id: cmdIds.paste,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -327,7 +327,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['deleteCell'],
+    id: cmdIds.deleteCell,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -336,7 +336,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['split'],
+    id: cmdIds.split,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -345,7 +345,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['merge'],
+    id: cmdIds.merge,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -354,7 +354,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['insertAbove'],
+    id: cmdIds.insertAbove,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -363,7 +363,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['insertBelow'],
+    id: cmdIds.insertBelow,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -372,7 +372,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['selectAbove'],
+    id: cmdIds.selectAbove,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -381,7 +381,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['selectBelow'],
+    id: cmdIds.selectBelow,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -390,7 +390,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['extendAbove'],
+    id: cmdIds.extendAbove,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -399,7 +399,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['extendBelow'],
+    id: cmdIds.extendBelow,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -408,7 +408,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['toggleLines'],
+    id: cmdIds.toggleLines,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -417,7 +417,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['toggleAllLines'],
+    id: cmdIds.toggleAllLines,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         let nbWidget = tracker.activeWidget;
         let nbWidget = tracker.activeWidget;
@@ -426,7 +426,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['commandMode'],
+    id: cmdIds.commandMode,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         tracker.activeWidget.content.mode = 'command';
         tracker.activeWidget.content.mode = 'command';
@@ -434,7 +434,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['editMode'],
+    id: cmdIds.editMode,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         tracker.activeWidget.content.mode = 'edit';
         tracker.activeWidget.content.mode = 'edit';
@@ -442,7 +442,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['undo'],
+    id: cmdIds.undo,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         NotebookActions.undo(tracker.activeWidget.content);
         NotebookActions.undo(tracker.activeWidget.content);
@@ -450,7 +450,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['redo'],
+    id: cmdIds.redo,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         NotebookActions.redo(tracker.activeWidget.content);
         NotebookActions.redo(tracker.activeWidget.content);
@@ -458,7 +458,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['switchKernel'],
+    id: cmdIds.switchKernel,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         selectKernelForContext(tracker.activeWidget.context, tracker.activeWidget.node);
         selectKernelForContext(tracker.activeWidget.context, tracker.activeWidget.node);
@@ -466,7 +466,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['markdown1'],
+    id: cmdIds.markdown1,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 1);
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 1);
@@ -474,7 +474,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['markdown2'],
+    id: cmdIds.markdown2,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 2);
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 2);
@@ -482,7 +482,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['markdown3'],
+    id: cmdIds.markdown3,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 3);
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 3);
@@ -490,7 +490,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['markdown4'],
+    id: cmdIds.markdown4,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 4);
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 4);
@@ -498,7 +498,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['markdown5'],
+    id: cmdIds.markdown5,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 5);
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 5);
@@ -506,7 +506,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     }
     }
   },
   },
   {
   {
-    id: cmdIds['markdown6'],
+    id: cmdIds.markdown6,
     handler: () => {
     handler: () => {
       if (tracker.activeWidget) {
       if (tracker.activeWidget) {
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 6);
         NotebookActions.setMarkdownHeader(tracker.activeWidget.content, 6);
@@ -516,192 +516,192 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
   ]);
   ]);
   app.palette.add([
   app.palette.add([
   {
   {
-    command: cmdIds['run'],
+    command: cmdIds.run,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Run Cell(s)'
     text: 'Run Cell(s)'
   },
   },
   {
   {
-    command: cmdIds['runAndAdvance'],
+    command: cmdIds.runAndAdvance,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Run Cell(s) and Advance'
     text: 'Run Cell(s) and Advance'
   },
   },
   {
   {
-    command: cmdIds['runAndInsert'],
+    command: cmdIds.runAndInsert,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Run Cell(s) and Insert'
     text: 'Run Cell(s) and Insert'
   },
   },
   {
   {
-    command: cmdIds['interrupt'],
+    command: cmdIds.interrupt,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'Interrupt Kernel'
     text: 'Interrupt Kernel'
   },
   },
   {
   {
-    command: cmdIds['restart'],
+    command: cmdIds.restart,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'Restart Kernel'
     text: 'Restart Kernel'
   },
   },
   {
   {
-    command: cmdIds['restartClear'],
+    command: cmdIds.restartClear,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'Restart Kernel & Clear Outputs'
     text: 'Restart Kernel & Clear Outputs'
   },
   },
   {
   {
-    command: cmdIds['restartRunAll'],
+    command: cmdIds.restartRunAll,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'Restart Kernel & Run All'
     text: 'Restart Kernel & Run All'
   },
   },
   {
   {
-    command: cmdIds['runAll'],
+    command: cmdIds.runAll,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'Run All Cells'
     text: 'Run All Cells'
   },
   },
   {
   {
-    command: cmdIds['clearAllOutputs'],
+    command: cmdIds.clearAllOutputs,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'Clear All Outputs'
     text: 'Clear All Outputs'
   },
   },
   {
   {
-    command: cmdIds['clearOutputs'],
+    command: cmdIds.clearOutputs,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Clear Output(s)'
     text: 'Clear Output(s)'
   },
   },
   {
   {
-    command: cmdIds['toCode'],
+    command: cmdIds.toCode,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Convert to Code'
     text: 'Convert to Code'
   },
   },
   {
   {
-    command: cmdIds['toMarkdown'],
+    command: cmdIds.toMarkdown,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Convert to Markdown'
     text: 'Convert to Markdown'
   },
   },
   {
   {
-    command: cmdIds['toRaw'],
+    command: cmdIds.toRaw,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Convert to Raw'
     text: 'Convert to Raw'
   },
   },
   {
   {
-    command: cmdIds['cut'],
+    command: cmdIds.cut,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Cut Cell(s)'
     text: 'Cut Cell(s)'
   },
   },
   {
   {
-    command: cmdIds['copy'],
+    command: cmdIds.copy,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Copy Cell(s)'
     text: 'Copy Cell(s)'
   },
   },
   {
   {
-    command: cmdIds['paste'],
+    command: cmdIds.paste,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Paste Cell(s)'
     text: 'Paste Cell(s)'
   },
   },
   {
   {
-    command: cmdIds['deleteCell'],
+    command: cmdIds.deleteCell,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Delete Cell(s)'
     text: 'Delete Cell(s)'
   },
   },
   {
   {
-    command: cmdIds['split'],
+    command: cmdIds.split,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Split Cell'
     text: 'Split Cell'
   },
   },
   {
   {
-    command: cmdIds['merge'],
+    command: cmdIds.merge,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Merge Selected Cell(s)'
     text: 'Merge Selected Cell(s)'
   },
   },
   {
   {
-    command: cmdIds['insertAbove'],
+    command: cmdIds.insertAbove,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Insert Cell Above'
     text: 'Insert Cell Above'
   },
   },
   {
   {
-    command: cmdIds['insertBelow'],
+    command: cmdIds.insertBelow,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Insert Cell Below'
     text: 'Insert Cell Below'
   },
   },
   {
   {
-    command: cmdIds['selectAbove'],
+    command: cmdIds.selectAbove,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Select Cell Above'
     text: 'Select Cell Above'
   },
   },
   {
   {
-    command: cmdIds['selectBelow'],
+    command: cmdIds.selectBelow,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Select Cell Below'
     text: 'Select Cell Below'
   },
   },
   {
   {
-    command: cmdIds['extendAbove'],
+    command: cmdIds.extendAbove,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Extend Selection Above'
     text: 'Extend Selection Above'
   },
   },
   {
   {
-    command: cmdIds['extendBelow'],
+    command: cmdIds.extendBelow,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Extend Selection Below'
     text: 'Extend Selection Below'
   },
   },
   {
   {
-    command: cmdIds['toggleLines'],
+    command: cmdIds.toggleLines,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Toggle Line Numbers'
     text: 'Toggle Line Numbers'
   },
   },
   {
   {
-    command: cmdIds['toggleAllLines'],
+    command: cmdIds.toggleAllLines,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'Toggle All Line Numbers'
     text: 'Toggle All Line Numbers'
   },
   },
   {
   {
-    command: cmdIds['editMode'],
+    command: cmdIds.editMode,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'To Edit Mode'
     text: 'To Edit Mode'
   },
   },
   {
   {
-    command: cmdIds['commandMode'],
+    command: cmdIds.commandMode,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'To Command Mode'
     text: 'To Command Mode'
   },
   },
   {
   {
-    command: cmdIds['switchKernel'],
+    command: cmdIds.switchKernel,
     category: 'Notebook Operations',
     category: 'Notebook Operations',
     text: 'Switch Kernel'
     text: 'Switch Kernel'
   },
   },
   {
   {
-    command: cmdIds['undo'],
+    command: cmdIds.undo,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Undo Cell Operation'
     text: 'Undo Cell Operation'
   },
   },
   {
   {
-    command: cmdIds['redo'],
+    command: cmdIds.redo,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Redo Cell Operation'
     text: 'Redo Cell Operation'
   },
   },
   {
   {
-    command: cmdIds['markdown1'],
+    command: cmdIds.markdown1,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Markdown Header 1'
     text: 'Markdown Header 1'
   },
   },
   {
   {
-    command: cmdIds['markdown1'],
+    command: cmdIds.markdown2,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Markdown Header 2'
     text: 'Markdown Header 2'
   },
   },
   {
   {
-    command: cmdIds['markdown1'],
+    command: cmdIds.markdown3,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Markdown Header 3'
     text: 'Markdown Header 3'
   },
   },
   {
   {
-    command: cmdIds['markdown1'],
+    command: cmdIds.markdown4,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Markdown Header 4'
     text: 'Markdown Header 4'
   },
   },
   {
   {
-    command: cmdIds['markdown1'],
+    command: cmdIds.markdown5,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Markdown Header 5'
     text: 'Markdown Header 5'
   },
   },
   {
   {
-    command: cmdIds['markdown1'],
+    command: cmdIds.markdown6,
     category: 'Notebook Cell Operations',
     category: 'Notebook Cell Operations',
     text: 'Markdown Header 6'
     text: 'Markdown Header 6'
   }
   }

+ 10 - 20
src/shortcuts/plugin.ts

@@ -35,21 +35,11 @@ const SHORTCUTS = [
     selector: 'body',
     selector: 'body',
     sequence: ['Accel Shift P']
     sequence: ['Accel Shift P']
   },
   },
-  {
-    command: 'command-palette:hide',
-    selector: 'body[data-left-area="command-palette"]',
-    sequence: ['Escape']
-  },
   {
   {
     command: 'file-browser:toggle',
     command: 'file-browser:toggle',
     selector: 'body',
     selector: 'body',
     sequence: ['Accel Shift F']
     sequence: ['Accel Shift F']
   },
   },
-  {
-    command: 'file-browser:hide',
-    selector: 'body[data-left-area="file-browser"]',
-    sequence: ['Escape']
-  },
   {
   {
     command: 'file-operations:new-text-file',
     command: 'file-operations:new-text-file',
     selector: 'body',
     selector: 'body',
@@ -81,17 +71,12 @@ const SHORTCUTS = [
     sequence: ['Accel Shift H']
     sequence: ['Accel Shift H']
   },
   },
   {
   {
-    command: 'help-doc:hide',
-    selector: 'body[data-right-area="help-doc"]',
-    sequence: ['Escape']
-  },
-  {
-    command: 'notebook-cells:runAndAdvance',
+    command: 'notebook-cells:run-and-advance',
     selector: '.jp-Notebook',
     selector: '.jp-Notebook',
     sequence: ['Shift Enter']
     sequence: ['Shift Enter']
   },
   },
   {
   {
-    command: 'notebook-cells:runAndInsert',
+    command: 'notebook-cells:run-and-insert',
     selector: '.jp-Notebook',
     selector: '.jp-Notebook',
     sequence: ['Alt Enter']
     sequence: ['Alt Enter']
   },
   },
@@ -206,7 +191,7 @@ const SHORTCUTS = [
     sequence: ['ArrowDown']
     sequence: ['ArrowDown']
   },
   },
   {
   {
-    command: 'notebook-cells:toggle-lineNumbers',
+    command: 'notebook-cells:toggle-line-numbers',
     selector: '.jp-Notebook.jp-mod-commandMode',
     selector: '.jp-Notebook.jp-mod-commandMode',
     sequence: ['L']
     sequence: ['L']
   },
   },
@@ -241,12 +226,12 @@ const SHORTCUTS = [
     sequence: ['6']
     sequence: ['6']
   },
   },
   {
   {
-    command: 'notebook:editMode',
+    command: 'notebook:edit-mode',
     selector: '.jp-Notebook.jp-mod-commandMode',
     selector: '.jp-Notebook.jp-mod-commandMode',
     sequence: ['Enter']
     sequence: ['Enter']
   },
   },
   {
   {
-    command: 'notebook:commandMode',
+    command: 'notebook:command-mode',
     selector: '.jp-Notebook.jp-mod-editMode',
     selector: '.jp-Notebook.jp-mod-editMode',
     sequence: ['Escape']
     sequence: ['Escape']
   },
   },
@@ -255,6 +240,11 @@ const SHORTCUTS = [
     selector: '.jp-Console .jp-CellEditor',
     selector: '.jp-Console .jp-CellEditor',
     sequence: ['Shift Enter']
     sequence: ['Shift Enter']
   },
   },
+  {
+    command: 'console:dismiss-overlays',
+    selector: '.jp-Console .jp-CellEditor',
+    sequence: ['Escape']
+  },
 ];
 ];
 
 
 
 

+ 29 - 25
test/src/notebook/completion/widget.spec.ts

@@ -212,13 +212,40 @@ describe('notebook/completion/widget', () => {
 
 
     });
     });
 
 
+    describe('#reset()', () => {
+
+      it('should reset the completion widget', () => {
+        let anchor = new Widget();
+        let model = new CompletionModel();
+        let options: CompletionWidget.IOptions = {
+          model, anchor: anchor.node
+        };
+        model.options = ['foo', 'bar'];
+        anchor.attach(document.body);
+
+        let widget = new CompletionWidget(options);
+
+        widget.attach(document.body);
+        sendMessage(widget, Widget.MsgUpdateRequest);
+        expect(widget.isHidden).to.be(false);
+        expect(model.options).to.be.ok();
+        widget.reset();
+        sendMessage(widget, Widget.MsgUpdateRequest);
+        expect(widget.isHidden).to.be(true);
+        expect(model.options).to.not.be.ok();
+        widget.dispose();
+        anchor.dispose();
+      });
+
+    });
+
     describe('#handleEvent()', () => {
     describe('#handleEvent()', () => {
 
 
-      it('should handle window keydown and mousedown events', () => {
+      it('should handle document keydown and mousedown events', () => {
         let widget = new LogWidget();
         let widget = new LogWidget();
         widget.attach(document.body);
         widget.attach(document.body);
         ['keydown', 'mousedown'].forEach(type => {
         ['keydown', 'mousedown'].forEach(type => {
-          simulate(window, type);
+          simulate(document, type);
           expect(widget.events).to.contain(type);
           expect(widget.events).to.contain(type);
         });
         });
         widget.dispose();
         widget.dispose();
@@ -258,29 +285,6 @@ describe('notebook/completion/widget', () => {
           anchor.dispose();
           anchor.dispose();
         });
         });
 
 
-        it('should reset on escape key', () => {
-          let anchor = new Widget();
-          let model = new CompletionModel();
-          let options: CompletionWidget.IOptions = {
-            model, anchor: anchor.node
-          };
-          model.options = ['foo', 'bar'];
-          anchor.attach(document.body);
-
-          let widget = new CompletionWidget(options);
-
-          widget.attach(document.body);
-          sendMessage(widget, Widget.MsgUpdateRequest);
-          expect(widget.isHidden).to.be(false);
-          expect(model.options).to.be.ok();
-          simulate(anchor.node, 'keydown', { keyCode: 27 }); // Escape
-          sendMessage(widget, Widget.MsgUpdateRequest);
-          expect(widget.isHidden).to.be(true);
-          expect(model.options).to.not.be.ok();
-          widget.dispose();
-          anchor.dispose();
-        });
-
         it('should trigger a selected signal on enter key', () => {
         it('should trigger a selected signal on enter key', () => {
           let anchor = new Widget();
           let anchor = new Widget();
           let model = new CompletionModel();
           let model = new CompletionModel();