Browse Source

Add tooltip dismiss command.

Afshin Darian 7 years ago
parent
commit
9760e340c7

+ 19 - 1
packages/shortcuts-extension/schema/jupyter.extensions.shortcuts.json

@@ -289,7 +289,7 @@
         "command": { "default": "notebook:enter-command-mode" },
         "keys": { "default": ["Escape"] },
         "selector": {
-          "default": ".jp-Notebook.jp-mod-editMode:not(.jp-Tooltip-anchor)"
+          "default": ".jp-Notebook.jp-mod-editMode"
         }
       },
       "type": "object"
@@ -546,6 +546,24 @@
       },
       "type": "object"
     },
+    "tooltip:dismiss-console": {
+      "default": { },
+      "properties": {
+        "command": { "default": "tooltip:dismiss" },
+        "keys": { "default": ["Escape"] },
+        "selector": { "default": "body.jp-mod-tooltip .jp-CodeConsole" }
+      },
+      "type": "object"
+    },
+    "tooltip:dismiss-notebook": {
+      "default": { },
+      "properties": {
+        "command": { "default": "tooltip:dismiss" },
+        "keys": { "default": ["Escape"] },
+        "selector": { "default": "body.jp-mod-tooltip .jp-Notebook" }
+      },
+      "type": "object"
+    },
     "tooltip:launch-console": {
       "default": { },
       "properties": {

+ 14 - 1
packages/tooltip-extension/src/index.ts

@@ -42,6 +42,9 @@ import {
  * The command IDs used by the tooltip plugin.
  */
 namespace CommandIDs {
+  export
+  const dismiss = 'tooltip:dismiss';
+
   export
   const launchConsole = 'tooltip:launch-console';
 
@@ -60,6 +63,17 @@ const service: JupyterLabPlugin<ITooltipManager> = {
   provides: ITooltipManager,
   activate: (app: JupyterLab): ITooltipManager => {
     let tooltip: Tooltip | null = null;
+
+    // Add tooltip dismiss command.
+    app.commands.addCommand(CommandIDs.dismiss, {
+      execute: () => {
+        if (tooltip) {
+          tooltip.dispose();
+          tooltip = null;
+        }
+      }
+    });
+
     return {
       invoke(options: ITooltipManager.IOptions): Promise<void> {
         const detail: 0 | 1 = 0;
@@ -141,7 +155,6 @@ const notebookPlugin: JupyterLabPlugin<void> = {
         }
       }
     });
-
   }
 };