소스 검색

more focus cleanup

Steven Silvester 7 년 전
부모
커밋
4ff4c5f043
1개의 변경된 파일13개의 추가작업 그리고 10개의 파일을 삭제
  1. 13 10
      packages/notebook/src/widget.ts

+ 13 - 10
packages/notebook/src/widget.ts

@@ -1354,25 +1354,27 @@ class Notebook extends StaticNotebook {
    */
   private _evtMouseDown(event: MouseEvent): void {
 
-    // Mouse click should always ensure the notebook is focused.
-    this._ensureFocus(true);
-
     // We only handle main or secondary button actions.
     if (!(event.button === 0 || event.button === 2)) {
       return;
     }
 
     // Try to find the cell associated with the event.
-    let target = event.target as HTMLElement;
-    let index = this._findCell(target);
+    // We cannot use `event.target` because it sometimes gives an orphaned
+    // node in Firefox 57.
+    let target = document.elementFromPoint(event.clientX, event.clientY);
+    let index = this._findCell(target as HTMLElement);
     let widget = this.widgets[index];
 
-
     // Switch to command mode if the click is not in an editor.
     if (index === -1 || !widget.editorWidget.node.contains(target)) {
       this.mode = 'command';
+    } else if (index !== -1) {
+      this.mode = 'edit';
     }
 
+    // Mouse click should always ensure the notebook is focused.
+    this._ensureFocus(true);
 
     // Secondary click deselects cells and possibly changes the active cell.
     if (event.button === 2) {
@@ -1383,8 +1385,6 @@ class Notebook extends StaticNotebook {
       return;
     }
 
-
-
     if (index !== -1) {
 
       if (event.shiftKey) {
@@ -1731,8 +1731,11 @@ class Notebook extends StaticNotebook {
     if (!model) {
       return;
     }
-    let target = event.target as HTMLElement;
-    let i = this._findCell(target);
+
+    // We cannot use `event.target` because it sometimes gives an orphaned
+    // node in Firefox 57.
+    let target = document.elementFromPoint(event.clientX, event.clientY);
+    let i = this._findCell(target as HTMLElement);
     if (i === -1) {
       return;
     }