Skip to content

Commit

Permalink
fix: prevent errors when focus gets lost on new tag
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Sep 7, 2020
1 parent 148f7d7 commit d458915
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/assets/javascripts/views/tags/tags_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -295,13 +298,26 @@ 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 {
return this.saveTagRename(tag);
}
}

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) {
Expand Down

0 comments on commit d458915

Please sign in to comment.