Browse Source

Fix split cell handling

Steven Silvester 8 years ago
parent
commit
4d9983a5e1
2 changed files with 21 additions and 13 deletions
  1. 1 0
      src/notebook/notebook/actions.ts
  2. 20 13
      src/notebook/notebook/widget.ts

+ 1 - 0
src/notebook/notebook/actions.ts

@@ -86,6 +86,7 @@ namespace NotebookActions {
 
     widget.activeCellIndex++;
     widget.scrollToActiveCell();
+    widget.activate();
   }
 
   /**

+ 20 - 13
src/notebook/notebook/widget.ts

@@ -857,7 +857,7 @@ class Notebook extends StaticNotebook {
    * Handle `'activate-request'` messages.
    */
   protected onActivateRequest(msg: Message): void {
-    this.node.focus();
+    this._ensureFocus();
   }
 
   /**
@@ -867,18 +867,7 @@ class Notebook extends StaticNotebook {
     let activeCell = this.activeCell;
     // Ensure we have the correct focus.
     if (this.node.contains(document.activeElement)) {
-      if (this.mode === 'edit' && activeCell) {
-        activeCell.editor.activate();
-      } else {
-        // If an editor currently has focus, focus our node.
-        // Otherwise, another input field has focus and should keep it.
-        let w = find(this.layout, widget => {
-          return (widget as BaseCellWidget).editor.hasFocus();
-        });
-        if (w) {
-          this.node.focus();
-        }
-      }
+      this._ensureFocus();
     }
 
     // Set the appropriate classes on the cells.
@@ -970,6 +959,24 @@ class Notebook extends StaticNotebook {
     }
   }
 
+  private _ensureFocus(): void {
+    let activeCell = this.activeCell;
+    if (this.mode === 'edit' && activeCell) {
+      activeCell.editor.activate();
+    } else if (!this.node.contains(document.activeElement)) {
+      this.node.focus();
+    } else {
+      // If an editor currently has focus, focus our node.
+      // Otherwise, another input field has focus and should keep it.
+      let w = find(this.layout, widget => {
+        return (widget as BaseCellWidget).editor.hasFocus();
+      });
+      if (w) {
+        this.node.focus();
+      }
+    }
+  }
+
   /**
    * Find the cell index containing the target html element.
    *