From d45891569f2d87ff70a0b828a03658d1335187b7 Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Mon, 7 Sep 2020 15:39:59 +0200 Subject: [PATCH] fix: prevent errors when focus gets lost on new tag --- app/assets/javascripts/views/tags/tags_view.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/assets/javascripts/views/tags/tags_view.ts b/app/assets/javascripts/views/tags/tags_view.ts index 6f9aa1bed30..69a57f38e44 100644 --- a/app/assets/javascripts/views/tags/tags_view.ts +++ b/app/assets/javascripts/views/tags/tags_view.ts @@ -175,6 +175,9 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> { } const noteCounts: NoteCounts = {}; for (const tag of allTags) { + if (tag === this.state.templateTag) { + continue; + } if (tag.isSmartTag()) { /** Other smart tags do not contain counts */ if (tag.isAllTag) { @@ -295,6 +298,9 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> { async saveTag($event: Event, tag: SNTag) { ($event.target! as HTMLInputElement).blur(); + if (!this.titles[tag.uuid]?.length) { + return this.undoCreateTag(tag); + } if (this.getState().templateTag) { return this.saveNewTag(); } else { @@ -302,6 +308,16 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> { } } + private async undoCreateTag(tag: SNTag) { + await this.setState({ + templateTag: undefined, + editingTag: undefined, + selectedTag: this.appState.selectedTag, + tags: this.state.tags.filter(existingTag => existingTag !== tag) + }); + delete this.titles[tag.uuid]; + } + async saveTagRename(tag: SNTag) { const newTitle = this.titles[tag.uuid] || ''; if (newTitle.length === 0) {