diff --git a/app/assets/javascripts/views/tags/tags_view.ts b/app/assets/javascripts/views/tags/tags_view.ts index 6f9aa1bed..69a57f38e 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) {