From ed3262ff9470ec3660d713edf61050f32477ad76 Mon Sep 17 00:00:00 2001 From: markellekelly Date: Fri, 6 Dec 2019 12:02:17 -0800 Subject: [PATCH] fixed focus problem when changing tabs + removed console logs --- packages/celltags/src/addwidget.ts | 26 ++++++++++++++++++++++---- packages/celltags/src/tool.ts | 2 -- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/celltags/src/addwidget.ts b/packages/celltags/src/addwidget.ts index 3b97863c4090..3088b5afdae1 100644 --- a/packages/celltags/src/addwidget.ts +++ b/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. * diff --git a/packages/celltags/src/tool.ts b/packages/celltags/src/tool.ts index e4e8cf94dcf1..03ba10778423 100644 --- a/packages/celltags/src/tool.ts +++ b/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')); } /**