Browse Source

Fix handling of codemirror focus and dialog in notebook

Steven Silvester 7 years ago
parent
commit
4979925923

+ 1 - 1
buildutils/src/add-sibling.ts

@@ -38,7 +38,7 @@ if (fs.existsSync(packagePath)) {
 } else {
   // Otherwise treat it as a git reposotory and try to add it.
   packageDirName = target.split('/').pop().split('.')[0];
-  let packagePath = path.join(basePath, 'packages', packageDirName);
+  packagePath = path.join(basePath, 'packages', packageDirName);
   utils.run('git clone ' + target + ' ' + packagePath);
 }
 

+ 1 - 0
package.json

@@ -31,6 +31,7 @@
     "publish": "jlpm run clean:slate && jlpm run build:packages && lerna publish --force-publish=* -m \"Publish\" && jlpm run build:update",
     "remove:dependency": "node buildutils/lib/remove-dependency.js",
     "remove:package": "node buildutils/lib/remove-package.js",
+    "remove:sibling": "node buildutils/lib/remove-package.js",
     "test": "cd test && jlpm test",
     "test:chrome": "lerna run test:chrome --stream",
     "test:firefox": "lerna run test:firefox --stream",

+ 2 - 2
packages/codemirror/src/editor.ts

@@ -40,9 +40,9 @@ import {
   Mode
 } from './mode';
 
+import 'codemirror/addon/comment/comment.js';
 import 'codemirror/addon/edit/matchbrackets.js';
 import 'codemirror/addon/edit/closebrackets.js';
-import 'codemirror/addon/comment/comment.js';
 import 'codemirror/addon/scroll/scrollpastend.js';
 import 'codemirror/addon/search/searchcursor';
 import 'codemirror/addon/search/search';
@@ -327,7 +327,7 @@ class CodeMirrorEditor implements CodeEditor.IEditor {
    * Test whether the editor has keyboard focus.
    */
   hasFocus(): boolean {
-    return this._editor.hasFocus();
+    return this._editor.getWrapperElement().contains(document.activeElement);
   }
 
   /**

+ 5 - 6
packages/codemirror/style/index.css

@@ -36,6 +36,11 @@
 }
 
 
+.CodeMirror-dialog {
+  background-color: var(--jp-layout-color0);
+}
+
+
 /* This causes https://github.com/jupyter/jupyterlab/issues/522 */
 /* May not cause it not because we changed it! */
 .CodeMirror-lines {
@@ -58,12 +63,6 @@
 }
 
 
-/* Hide dialogs in inline editors due to poor UX with small editors. */
-.jp-CodeMirrorEditor[data-type="inline"] .CodeMirror-dialog {
-  display: none;
-}
-
-
 .CodeMirror-cursor {
   border-left: 1.4px solid var(--jp-editor-cursor-color);
 }

+ 5 - 2
packages/notebook/src/widget.ts

@@ -1316,7 +1316,9 @@ class Notebook extends StaticNotebook {
   private _ensureFocus(force=false): void {
     let activeCell = this.activeCell;
     if (this.mode === 'edit' && activeCell) {
-      activeCell.editor.focus();
+      if (!activeCell.editor.hasFocus()) {
+        activeCell.editor.focus();
+      }
     } else if (activeCell) {
       activeCell.editor.blur();
     }
@@ -1418,8 +1420,9 @@ class Notebook extends StaticNotebook {
           this._mouseMode = 'couldDrag';
           document.addEventListener('mouseup', this, true);
           document.addEventListener('mousemove', this, true);
+          event.preventDefault();
         }
-        event.preventDefault();
+
       }
 
     }