fix: prevent errors when focus gets lost on new tag

This commit is contained in:
Baptiste Grob
2020-09-07 15:39:59 +02:00
parent 148f7d7603
commit d45891569f

View File

@@ -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) {