Przeglądaj źródła

fixed focus problem when changing tabs + removed console logs

markellekelly 5 lat temu
rodzic
commit
8f57a91674
2 zmienionych plików z 22 dodań i 6 usunięć
  1. 22 4
      packages/celltags/src/addwidget.ts
  2. 0 2
      packages/celltags/src/tool.ts

+ 22 - 4
packages/celltags/src/addwidget.ts

@@ -52,6 +52,7 @@ export class AddWidget extends Widget {
   onAfterAttach() {
     this.node.addEventListener('mousedown', this);
     this.input.addEventListener('keydown', this);
+    this.input.addEventListener('focus', this);
     this.input.addEventListener('blur', this);
   }
 
@@ -61,6 +62,7 @@ export class AddWidget extends Widget {
   onBeforeDetach() {
     this.node.removeEventListener('mousedown', this);
     this.input.removeEventListener('keydown', this);
+    this.input.removeEventListener('focus', this);
     this.input.removeEventListener('blur', this);
   }
 
@@ -85,6 +87,9 @@ export class AddWidget extends Widget {
       case 'blur':
         this._evtBlur();
         break;
+      case 'focus':
+        this._evtFocus();
+        break;
       default:
         break;
     }
@@ -101,14 +106,27 @@ export class AddWidget extends Widget {
       this.input.value = '';
       this.input.focus();
     } else if (event.target !== this.input) {
-      let value = this.input.value;
-      (this.parent as TagTool).addTag(value);
-      this.input.blur();
-      this._evtBlur();
+      if (this.input.value !== '') {
+        let value = this.input.value;
+        (this.parent as TagTool).addTag(value);
+        this.input.blur();
+        this._evtBlur();
+      }
     }
     event.preventDefault();
   }
 
+  /**
+   * Handle the `'focus'` event for the input box.
+   *
+   * @param event - The DOM event sent to the widget
+   */
+  private _evtFocus() {
+    if (!this.editing) {
+      this.input.blur();
+    }
+  }
+
   /**
    * Handle the `'keydown'` event for the input box.
    *

+ 0 - 2
packages/celltags/src/tool.ts

@@ -78,7 +78,6 @@ export class TagTool extends NotebookTools.Tool {
     cell.model.metadata.set('tags', tags);
     this.refreshTags();
     this.loadActiveTags();
-    console.log(this.tracker.activeCell.model.metadata.get('tags'));
   }
 
   /**
@@ -99,7 +98,6 @@ export class TagTool extends NotebookTools.Tool {
     }
     this.refreshTags();
     this.loadActiveTags();
-    console.log(this.tracker.activeCell.model.metadata.get('tags'));
   }
 
   /**